Dotnet, DotnetCore, Azure, C#,VB.net, Sql Server, WCF, MVC ,Linq, Javascript and Jquery
28 June 2015
Ajax call in MVC
The first thing to look at is the key settings options that are available for AJAX requests:
type This is type of HTTP Request and accepts a valid HTTP verb. POST is the option illustrated in this article.
url This is the location of the resource that the request will be made to.
data This is the actual data to be sent as part of the request.
contentType This is the content type of the request you are making. The default is 'application/x-www-form-urlencoded'.
dataType This is the type of data you expect to receive back. Accepted values are text, xml, json, script, html jsonp. If you do not provide a value, jQuery will examine the MIME type of the response and base its decision on that.
Example
< script >
$( function () {
$( "button" ).click( function () {
var car = { Make: 'Audi', Model: 'A4 Avant', Colour: 'Black', Registered: 2013 };
$.ajax( {
type: "POST",
url: "/Receiver",
data: car,
datatype: "html",
success: function ( data ) {
$( '#result' ).html( data );
}
} );
});
} );
< /script >
Setting async false in ajax in MVC
Setting async to false means that the statement you are calling has to complete before the next statement in your function can be called. If you set async: true then that statement will begin it's execution and the next statement will be called regardless of whether the async statement has completed yet.
$( function () {
$( "button" ).click( function () {
var car = { Make: 'Audi', Model: 'A4 Avant', Colour: 'Black', Registered: 2013 };
$.ajax( {
type: "POST",
url: "/Receiver",
data: car,
async:false,
datatype: "html",
success: function ( data ) {
$( '#result' ).html( data );
}
} );
} );
} );
By default async is true in ajax call.
MVC Life Cycle
Step 1 Fill route: - MVC requests are mapped to route tables which in turn specify which controller and action to be invoked. So if the request is the first request the first thing is to fill the route table with routes collection. This filling of route table happens in the global.asax file.
Step 2 Fetch route:- Depending on the URL sent "UrlRoutingModule" searches the route table to create "RouteData" object which has the details of which controller and action to invoke.
Step 3 Request context created: - The "RouteData" object is used to create the "RequestContext" object.
Step 4 Controller instance created: - This request object is sent to "MvcHandler" instance to create the controller class instance. Once the controller class object is created it calls the "Execute" method of the controller class.
Creating Response object: - This phase has two steps executing the action and finally sending the response as a result to the view.
Step 5 Execute Action: - The "ControllerActionInvoker" determines which action to executed and executes the action.
Step 6 Result sent: - The action method executes and creates the type of result which can be a view result , file result , JSON result etc.
22 March 2015
WCF - Windows Communication Foundation
How IIS Process Asp.net request before Asp.net Page Life cycle
When client request for some information from a web server, request first reaches to HTTP.SYS of IIS. HTTP.SYS then send the request to respective Application Pool. Application Pool then forward the request to worker process to load the ISAPI Extension which will create an HTTPRuntime Object to Process the request via HTTPModule and HTTPHanlder. After that the ASP.NET Page LifeCycle events starts.
Worker Process: Worker Process (w3wp.exe) runs the ASP.Net application in IIS. This process is responsible to manage all the request and response that are coming from client system. All the ASP.Net functionality runs under the scope of worker process. When a request comes to the server from a client worker process is responsible to generate the request and response. In a single word we can say worker process is the heart of ASP.NET Web Application which runs on IIS.
Application Pool: Application pool is the container of worker process. Application pools is used to separate sets of IIS worker processes that share the same configuration. Application pools enables a better security, reliability, and availability for any web application. The worker process serves as the process boundary that separates each application pool so that when one worker process or application is having an issue or recycles, other applications or worker processes are not affected. This makes sure that a particular web application doesn’t not impact other web application as they they are configured into different application pools.
reference
http://abhijitjana.net/2010/03/14/beginner%E2%80%99s-guide-how-iis-process-asp-net-request/
Dependency Injection
Factory Method Patterns in C#
Implementing OAuth validation in a Web API
I mplementing OAuth validation in a Web API Implementing OAuth validation in a Web API using C# typically involves several key steps to sec...
-
ViewBag, ViewData, TempData and View State in MVC ASP.NET MVC offers us three options ViewData, ViewBag and TempData for passing data from...
-
// Export Datatable to Excel in C# Windows application using System; using System.Data; using System.IO; using System.Windows.Forms; ...