ASP.Net MVC: How Microsoft has explained the foundation
correlating with ASP.Net web forms.
If you are from ASP.Net Web Forms background. You must have
noticed that the request was based on two parts the physical location of the
file (e.g.http://localhost:8090/MyFirstPage.aspx) whose code-behind contains
the logic and some data passed via query string(FirstName and LastName passed
as querystring such as http://llocalhost:8090/MyFirstPage.aspx?FirstName=Ashish&LastName=Kalra).
This doesn’t mean that all the requests were possible by this mode only. If you
want to have some different request scheme you implement your adhoc custom
handler. Thus earlier also you can use ASP.Net to handle request regardless of
the dependencies on physical files.
Also people often get confused between URN, URI and URL. Let’s
quickly erase this doubt. URI (Uniform Resource Identifier) is used to refer to
a resource by location or a name. When the URI identifies the resource by
location it’s called URL (Uniform Resource Locator).When the URI identifies the
resource by name it become URN (Uniform Resource Name). I was also elated when I
learned this. Thanks to Microsoft books.
So if you examine carefully you come to one conclusion.
Although you can have user friendly URLs in ASP.Net web forms world but it
comes at the cost of hard coding all the combination and mapping the
combination in web.config.ASP.Net MVC came up with the flexible syntax by
adding a new component in the runtime pipeline (which intercepts requests, processes
the URL and triggers the ASP.NET MVC HTTP handler), known as URL routing HTTP
Module. To be more precise in ASP.NET MVC, URL routing serves the purpose of
mapping incoming URLs to a controller class and an action method. Don’t worry
we will come to the controller and action later on. But for now consider
Controller as a class and action as one of the class method.
Never forget MVC is just a design pattern which produced a
new framework-ASP.Net MVC. This framework takes use of the same ASP.Net runtime
which ASP.Net web forms is using. ASP.Net MVC is a loosely coupled architecture
where maintainability as well as testability of the solutions is easier to
perform.
The URL routing HTTP module supersedes the URL rewriting
feature of older versions of ASP.NET. URL rewriting exists to decouple the
requested URL from the physical webpage that serves the request. There is a
very good article in code project written by one of techie Rahul Rajat Singh
explaining how to perform URL rewriting using custom HTTP module. http://www.codeproject.com/Articles/335968/Implementing-HTTPHandler-and-HTTPModule-in-ASP-NET
Please go through it to have an idea of how URL rewriting can be done in
ASP.Net web forms.
Thus all we can conclude whenever a request pertaining to an
application hosted in IIS comes to the IIS.URL routing module intercepts the
request that couldn’t be served via old way of custom handler and custom
module. e.g. if the request is for .aspx page or extension mapped with IIS the
request is processed in terms of page handler. If the request is like
Home/Projects and a custom handler exists then also the request is processed
via custom handler. For other requests URL routing module comes into play and
the request goes into ASP.Net MVC space. If still the request can’t be
processed then Http 404 Error occurs. Conclusion is in ASP.Net MVC space the
request that match predefined URL patterns are allowed to take advantage of ASP.Net
MVC runtime. All such requests are routed to the common HTTP handler class that
instantiates the appropriate controller class and then invokes the action
method on it. The rest is all MVC patterns i.e. Model, View and Controller
around which the story of entire ASP.Net MVC application revolves.
No comments:
Post a Comment