Monday, March 30, 2020

How to deploy an ASP.NET Core app to a sub-folder inside Azure Web App (App Service).

If you don't know how to deploy application on azure app service kindly go refer this link 

By default Azure provides publish profiles for the Web App (To put files to the root of the domain). In our case, We wanted to deploy inside a sub-folder.

Suppose our web app name was demo-site and we want to web deploy the app under demo-site\sub-folder. To do that,

Download the publish profile.
Kindly refer this link

For upload the files we need filezilla or winscp i am using winscp  , you can install winscp from this link

follow this guide to get FTP credentials

when you installed winscp fill FTP details , Username and Password.

After successful login you have to upload the files in sub-folder. From source to target.

after upload successful Go to portal > demo-site App Service > Configuration > Path Mappings > Virtual applications and directories.

set sub-folder type = applications  Bowers the url.

Hope is work fine if facing any issue kindly send email to me.

Thank you,

Arjun Walmiki

How to deploy an ASP.NET Core app to Azure Web App (App Service)

Microsoft Azure app service is very famous recently i got task move my my azure VM host to app service.How to deploy an ASP.NET Core app to Azure Web App (App Service) or How to deploy an ASP.NET Core app to a sub-folder inside Azure Web App (App Service)pls refer this link

In this post i have show you "How to deploy an ASP.NET Core app to Azure Web App (App Service)".
I am using Visual code for web deploy.

 We want Azure App Service for Visual Studio Code (Preview)  Click here

when Azure App Service install and after login with your azure credential the screen are as below:-
In above screen i have already added my instance name.

We need to create workspace click in File => Add folder to workspace.
the screen are as below :-

Right click on folder select Deploy to web service option and select your app service rest of thing Azure will be take care.

Thank you

Arjun Walmiki





Saturday, March 21, 2020

How to determine the installed .NET Framework, .NET Core, and Functions Runtime versions in Azure App Services

 The Details for .NET Core and Functions, so I decided to write up a single post that covers all three.

First steps

The first thing we need to do is to open the Kudu Debug Console.
To do that, navigate to {yoursite}.scm.azurewebsites.net and then click on "Debug console" at the top. You can select either CMD or PowerShell.
Now that we have the console open...

.NET Framework

To find out the installed .NET Framework versions, type: ls "\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework"

ls -l and dir also work in place of ls, we're just listing the contents of the folder.
Or you can type: ls "\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App"

Functions Runtime

For the installed Azure Functions Runtime versions, type: ls "\Program Files (x86)\SiteExtensions\Functions"

The Kudu console supports pasting via Control-V for the commands above.
You can also select the "System Drive" icon in the file browser section at the top of the page and then navigate to the respective folders by clicking the folder links. Using the file browser will automatically change the current working directory in the console.

Thank you

Understand what versions of .NET are supported on Azure App Service

So how do you check to see what version of the .NET Framework Azure App Services Supports?
One of the easiest ways that I know of it to use an existing website that you created that is hosted on Azure App Services and go to the Development Tools and Advanced Tools and open the Kudu Portal.


Then to go the Debug console and then CMD.

Type cd D:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework
Type dir
You'll see a list of the supported .NET Frameworks!
Thank you


Friday, March 13, 2020

How to insert value into primary key column in SQL Server?

if you got this error message when trying to run this SQL: An explicit value for the identity column in table 'Student' can only be specified when a column list is used and IDENTITY_INSERT is ON.
Used below query 

SET IDENTITY_INSERT StudentON;
Insert into Student(classID,ClassName,schoolID) values(1976,'Grade 1',178)
SET IDENTITY_INSERT Student OFF;

===================================================================
Thank you 

Friday, March 6, 2020

Multiple Connection String

Dear All,

In this post i have explain you multiple connection string

XML Connection String:-
protected void Button2_Click(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        StreamReader path = new StreamReader("D:\\myXmlData.xml");
        // string path = Server.MapPath("~/myXmlData.xml");
        ds.ReadXml(path);
        SqlConnection con = new SqlConnection(Tallystrsqlcon);
        SqlBulkCopy sbc = new SqlBulkCopy(con);
        sbc.DestinationTableName = "mtblUser";
        sbc.ColumnMappings.Add("Sno", "Sno");
        sbc.ColumnMappings.Add("UserId", "UserId");
        sbc.ColumnMappings.Add("Password", "Password");
        sbc.ColumnMappings.Add("UserName", "UserName");
        sbc.ColumnMappings.Add("Email", "Email");
        sbc.ColumnMappings.Add("GroupIn", "GroupIn");
        sbc.ColumnMappings.Add("UserType", "UserType");
        sbc.ColumnMappings.Add("EmpID", "EmpID");
        sbc.ColumnMappings.Add("Designation", "Designation");
        sbc.ColumnMappings.Add("SubGroup", "SubGroup");
        sbc.ColumnMappings.Add("ViewGroup", "ViewGroup");
        sbc.ColumnMappings.Add("Status", "Status");
        try
        {
            con.Open();
            sbc.WriteToServer(ds.Tables[0]);
            SqlCommand cmd = new SqlCommand("Select Sno, UserName,Designation from mtblUser", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds1 = new DataSet();
            da.Fill(ds1);
            GridView1.DataSource = ds1;
            GridView1.DataBind();


        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());

        }
        finally
        {
            System.Threading.Thread.Sleep(20000);
            con.Close();
           // Label1.Text = "Records Added Successfully !";
        }

    }

Fox Pro Connection String:-
<add name="strCon" connectionString="provider=VFPOLEDB.1 ;data source= 'C:\Program Files (x86)\Microsoft Visual FoxPro OLE DB Provider\Samples\Northwind';password='';user id=''"/>

OleDbConnection connection = new OleDbConnection(
    "Provider=VFPOLEDB.1;Data Source=.\\Northwind\\Northwind.dbc;"
);
connection.Open();
DataTable tables = connection.GetSchema(
    System.Data.OleDb.OleDbMetaDataCollectionNames.Tables
);

foreach (System.Data.DataRow rowTables in tables.Rows)
{
    Console.Out.WriteLine(rowTables["table_name"].ToString());
    DataTable columns = connection.GetSchema(
        System.Data.OleDb.OleDbMetaDataCollectionNames.Columns,
        new String[] { null, null, rowTables["table_name"].ToString(), null }
    );
    foreach (System.Data.DataRow rowColumns in columns.Rows)
    {
        Console.Out.WriteLine(
            rowTables["table_name"].ToString() + "." +
            rowColumns["column_name"].ToString() + " = " +
            rowColumns["data_type"].ToString()
        );
    }
}

Excel 2007:-
String constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + "D:\\Simple.xlsx" + ";Extended Properties='Excel 12.0 XML;HDR=YES;';";
        OleDbConnection con = new OleDbConnection(constr);
        OleDbCommand oconn = new OleDbCommand("Select [EmpID],[EmpName],[Designation] from [Employee$]", con);
        con.Open();
        OleDbDataAdapter sda = new OleDbDataAdapter(oconn);

=======================================================
Thank you


How to make custom Task Scheduler in asp.net c# using thread

In asp.net there are needs for performing few activities periodically. For that  we can use some class libraries or third party component to schedule a task or function to execute periodically.

Recently i found following simplest way to execute periodically any code.

Suppose you have  a class and routine as follow in App_Code/CS,

public class ClassABC
{
public static void SomeFunctionToRunPeriodically()
{
try
{
System.IO.File.WriteAllText(System.Web.Hosting.HostingEnvironment.MapPath(“~/LatestRunSaved.txt”), “Last Run of function at : ” + DateTime.Now.ToString() + Environment.NewLine);
}
catch (Exception ex)
{
string t = ex.Message;
}
System.Threading.Thread.Sleep(20000);
SomeFunctionToRunPeriodically();    //calling self after interval

}
public ClassABC()
{
//
// TODO: Add constructor logic here
//
}
}

If you notice in above function then its calling to itself after interval.

Now in global application file ‘global.asax’  inside application start event use following lines to create a new thread based call to a function above.

void Application_Start(object sender, EventArgs e)
{
System.Threading.Thread obj = new System.Threading.Thread(new System.Threading.ThreadStart(ClassABC.SomeFunctionToRunPeriodically));
obj.Name = “AnyTestName”;
obj.IsBackground = true;
obj.Start();
}

New thread based function call will run until your application is running in IIS process, It is a background process. 
Other routine things on site will work normally without problem.

===================================================
Thank you 

Top 10 WCF Interview Questions


Top 10 WCF Interview Questions



This Top WCF Tutorials post has most important and basic questions that are asked during a WCF interview on hot topics with detailed answers and explanation.


1. What is the difference between WCF and ASMX Web Services?

Simple and basic difference is that ASMX or ASP.NET web service is designed to send and receive messages using SOAP over HTTP only. While WCF can exchange messages using any format (SOAP is default) over any transport protocol (HTTP, TCP/IP, MSMQ, NamedPipes etc).

Another tutorial WCF Vs ASMX has detailed discussion on it.


2. What are WCF Service Endpoints? Explain.

For Windows Communication Foundation services to be consumed, it’s necessary that it must be exposed; Clients need information about service to communicate with it. This is where service endpoints play their role.

A WCF service endpoint has three basic elements i.e. Address, Binding and Contract.

Address: It defines “WHERE”. Address is the URL that identifies the location of the service.
Binding: It defines “HOW”. Binding defines how the service can be accessed.
Contract: It defines “WHAT”. Contract identifies what is exposed by the service.


3. What are the possible ways of hosting a WCF service? Explain.

For a Windows Communication Foundation service to host, we need at least a managed process, a ServiceHost instance and an Endpoint configured. Possible approaches for hosting a service are:

      1.    Hosting in a Managed Application/ Self Hosting
             a.    Console Application
             b.    Windows Application
             c.    Windows Service
        2.    Hosting on Web Server
             a.    IIS 6.0 (ASP.NET Application supports only HTTP)
             b.    Windows Process Activation Service (WAS) i.e. IIS 7.0 supports HTTP, TCP,
                    NamedPipes, MSMQ.


4. How we can achieve Operation Overloading while exposing WCF Services?

By default, WSDL doesn’t support operation overloading. Overloading behavior can be achieved by using “Name” property of OperationContract attribute.

[ServiceContract]
interface IMyCalculator
{
   [OperationContract(Name = "SumInt")]
   int Sum(int arg1,int arg2);


   [OperationContract(Name = "SumDouble")]
   double Sum(double arg1,double arg2);
}

When the proxy will be generated for these operations, it will have 2 methods with different names i.e. SumInt and SumDouble.


5. What Message Exchange Patterns (MEPs) supported by WCF? Explain each of them briefly.

       1.     Request/Response
       2.    One Way
       3.    Duplex

Request/Response
It’s the default pattern. In this pattern, a response message will always be generated to consumer when the operation is called, even with the void return type. In this scenario, response will have empty SOAP body.
One Way
In some cases, we are interested to send a message to service in order to execute certain business functionality but not interested in receiving anything back. OneWay MEP will work in such scenarios.
If we want queued message delivery, OneWay is the only available option.
Duplex
The Duplex MEP is basically a two-way message channel. In some cases, we want to send a message to service to initiate some longer-running processing and require a notification back from service in order to confirm that the requested process has been completed.



6. What is DataContractSerializer and How its different from XmlSerializer?

Serialization is the process of converting an object instance to a portable and transferable format. So, whenever we are talking about web services, serialization is very important.

Windows Communication Foundation has DataContractSerializer that is new in .NET 3.0 and uses opt-in approach as compared to XmlSerializer that uses opt-out. Opt-in means specify whatever we want to serialize while Opt-out means you don’t have to specify each and every property to serialize, specify only those you don’t want to serialize.
DataContractSerializer is about 10% faster than XmlSerializer but it has almost no control over how the object will be serialized. If we wanted to have more control over how object should be serialized that XmlSerializer is a better choice.


7. How we can use MessageContract partially with DataContract for a service operation in WCF?

MessageContract must be used all or none. If we are using MessageContract into an operation signature, then we must use MessageContract as the only parameter type and as the return type of the operation.


8. Which standard binding could be used for a service that was designed to replace an existing ASMX web service?


The basicHttpBinding standard binding is designed to expose a service as if it is an ASMX/ASP.NET web service. This will enable us to support existing clients as applications are upgrade to WCF.


9. Please explain briefly different Instance Modes in WCF?
WCF will bind an incoming message request to a particular service instance, so the available modes are:

Per Call: instance created for each call, most efficient in term of memory but need to maintain session.

Per Session: Instance created for a complete session of a user. Session is maintained.

Single: Only one instance created for all clients/users and shared among all.Least efficient in terms of memory.

Please follow "3 techniques for Instance Management in WCF".

10. Please explain different modes of security in WCF? Or Explain the difference between Transport and Message Level Security.

In Windows Communication Foundation, we can configure to use security at different levels

a.    Transport Level security means providing security at the transport layer itself. When dealing with security at Transport level, we are concerned about integrity, privacy and authentication of message as it travels along the physical wire. It depends on the binding being used that how WCF makes it secure because most of the bindings have built-in security.
                    
             <netTcpBinding>
            <binding name=”netTcpTransportBinding”>
               <security mode=”Transport”>
                          <Transport clientCredentialType=”Windows” />
               </security>
             </binding>
             </netTcpBinding>

b.    Message Level Security
For Tranport level security, we actually ensure the transport that is being used should be secured but in message level security, we actually secure the message. We encrypt the message before transporting it.

             <wsHttpBinding>
             <binding name=”wsHttpMessageBinding”>
               <security mode=”Message”>
                           <Message clientCredentialType=”UserName” />
               </security>
              </binding>
             </wsHttpBinding>

It totally depends upon the requirements but we can use a mixed security mode also as follows:

             <basicHttpBinding>
             <binding name=”basicHttp”>
               <security mode=”TransportWithMessageCredential”>
                          <Transport />
                               <Message clientCredentialType=”UserName” />
               </security>
             </binding>
             </basicHttpBinding>
 ============================================
Thank you  Hope it is help you