How does an asp.net MVC request fits in pipeline? - asp.net

As far as ASP.NET (.aspx) page request concern, I know that:
"Application Pool 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."
Now my question is, where does the ASP.NET MVC request (extension-less) fit into the above pipeline (as per the picture shown)? Where is it different? How does "aspnet_isapi.dll" find an extension-less URL?
Please advise!

Related

How to distinguish MVC and Web Forms Request in a Http Module

I have an ASP.Net web application which has both MVC and Web Forms. There is an Http Module (IHttpModule) to handle certain common tasks for both MVC and web forms. But now there few common things which should not happen for certain MVC actions.
Can anyone tell me.
How can I detect a given request is an MVC request or a web forms request inside the BeginRequest of the IHttpModule?
You can tell by the Viewstate in the page source. Check in Web Forms because the page has a __VIEWSTATE field
and for MVC
Check the HTTP response headers. ASP.NET MVC 1.0 generated pages will have:
X-Aspnetmvc-Version:1.0

Maintaining .net mvc session from classic asp pages

As a requirement our team has to implement session management for our application, redirecting users to the login page on session expiry. The problem is the website is a mixture of classic asp pages, .net web forms and asp.net mvc.
To keep the .net session alive we can use http GET requests to a dummy controller method that will redirect to the login page if the session has expired.
Because there are a considerable amount of page in the application it would be good to avoid having to put an include file on each page to refresh the .net session on each page load. Also for each ajax request made from classic asp we want to refresh the .net session.
An ideal solution to this would be to intercept each request made to the server, pass them through the dummy controller method to refresh the .net session, redirecting the user if the session has expired. I have looked at creating an ISAPI module for this as a possibility but am still unsure of the workload involved in creating such a module, or if I can create the desired behavior.
Is anyone in a similar situation or have a concrete solution to this problem?

ASP.Net routing from website root

Say I have a website www.abc123.com. What would be the best way to determine when users attempt to access pages like www.abc123.com/section1 and www.abc123.com/otherStuff ?
I've done some research and found that Request.PathInfo works quite well when the user visits www.abc123.com/Default.aspx/section1 but it does not work without having the Default.aspx portion included in the URL.
Right now all I get are 404 errors when attempting this with the built in IIS server in VS2k8 and on a published website. I'm using ASP.Net 3.5 and IIS 6 if those things matter.
This works better in IIS7 since it routes all request through the ASP.NET pipeline (not just requests for ASP.NET resources).
In IIS6, I think your best bet would be to write an HTTPModule. I think IIS passes all requests (not just requests for ASP.NET resources) through the HTTPModule pipeline.
In IIS7, you can just use your applications Global.asax to hook into the Application_BeginRequest event.
I am running 3.5 on IIS 6 and there are a few things to do, but it can be done. A post already covers this, look at ASP.NET routing on IIS 6.

Slow POST to ASP.NET MVC site from Webforms site

We have a WebForms+MVC 1.0 application where the WebForms site posts an encrypted string to an action in the MVC site which then displays a details view. However in our (clustered) test environment, the post from Webforms can take close to a minute before displaying the MVC view. The MVC action makes a WCF service call to get customer data from an Oracle database. This "slow post" effect only occurs when a user access the application for the first time - the second time around the response times are fast. Any ideas what could be causing this initial slow response time? Does it have to do something with the MVC routing? We don't experience this in our dev server environment.
Thanks
Are you sure that the MVC application is up and running when the first request comes in? The delay might simply be its load time.

IIS URL Rewriting vs URL Routing

I was planning to use url routing for a Web Forms application. But, after reading some posts, I am not sure if it is an easy approach.
Is it better to use the URL Rewrite module for web forms? But, it is only for IIS7. Initially, there was some buzz that URL routing is totally decoupled from Asp.Net MVC and it could be used for web forms.
Would love to hear any suggestions..
This is the best article I found about this topic: IIS URL Rewriting and ASP.NET routing by Ruslan Yakushev.
IIS URL Rewriting
When a client makes a request to the Web server for a particular URL, the URL-rewriting component analyzes the requested URL and changes it to a different other URL on the same server. The URL-rewriting component runs very early in the request processing pipeline, so is able to modify the requested URL before the Web server makes a decision about which handler to use for processing the request.
ASP.NET Routing
ASP.NET routing is implemented as a managed-code module that plugs into the IIS request processing pipeline at the Resolve Cache stage (PostResolveRequestCache event) and at the Map Handler stage (PostMapRequestHandler). ASP.NET routing is configured to run for all requests made to the Web application.
Differences between URL rewriting and ASP.NET routing:
URL rewriting is used to manipulate URL paths before the request is handled by the Web server. The URL-rewriting module does not know anything about what handler will eventually process the rewritten URL. In addition, the actual request handler might not know that the URL has been rewritten.
ASP.NET routing is used to dispatch a request to a handler based on the requested URL path. As opposed to URL rewriting, the routing component knows about handlers and selects the handler that should generate a response for the requested URL. You can think of ASP.NET routing as an advanced handler-mapping mechanism.
In addition to these conceptual differences, there are some functional differences between IIS URL rewriting and ASP.NET routing:
The IIS URL-rewrite module can be used with any type of Web application, which includes ASP.NET, PHP, ASP, and static files. ASP.NET routing can be used only with .NET Framework-based Web applications.
The IIS URL-rewrite module works the same way regardless of whether integrated or classic IIS pipeline mode is used for the application pool. For ASP.NET routing, it is preferable to use integrated pipeline mode. ASP.NET routing can work in classic mode, but in that case the application URLs must include file extensions or the application must be configured to use "*" handler mapping in IIS.
The URL-rewrite module can make rewriting decisions based on domain names, HTTP headers, and server variables. By default, ASP.NET routing works only with URL paths and with the HTTP-Method header.
In addition to rewriting, the URL-rewrite module can perform HTTP redirection, issue custom status codes, and abort requests. ASP.NET routing does not perform those tasks.
The URL-rewrite module is not extensible in its current version. ASP.NET routing is fully extensible and customizable.
There's a great post here about the differences between the two from a member of the IIS team.
One caveat I would advise is that for WebForms, you need to be careful when using Routing. I've written a sample implementation of how you'd use routing with WebForms that addresses these concerns and hopefully helps answer your question.
Do you want formatted urls to be a factory for spawning pages?
or do you want to make the .aspx go away?
rewriting, is for making the .aspx go away, or just to tidy up the url.
Routing, is for looking at a request and determining which object should handle it. They sound similar, phil haack has a few good articles on the subject.
in iis6, isapiRewrite, is very good
I recently just wrote my own rewriting system to make the URLs on my sites look better. Basically, you're going to need to write your own IHttpModule and add it to your web.config to intercept incoming requests. You can then use the HttpContext.Current.RewritePath to change what you're pointing at.
You'll also want to configure your site to use the aspnet_isapi for everything.
You'll discover a lot of little problems along the way like trying to work with pages that use "tails" on them (like for PageMethods), or pathing of page elements and form postbacks, but you'll get through them.
If interested, I can post a link to the code and you can check it out. I've worked a lot of the problems out already so you can read through it as you go. I'm sure there are a lot of other people that have done this as well that might be good resources as well.
You may want to check out my answer to this question: ASP.NET - Building your own routing system. I include some good references to help build your own routing system with either using the url rewriting method or the new routing engine that you can use that came out of the ASP.NET MVC project.
The Dynamic Data project that is available with .Net 3.5 SP1 shows a good example of a url routing implementation.
For URL Rewriting on IIS, IIRF works in IIS5, 6, 7. Free. Easy. Fast. Open Source. Regular expression support.

Resources