SiteCrafting, Inc.
1 Dec
ASP.net 2.0 and .htm or .html files
We have a CMS that generates static html files and some of those pages redirect to a different web page. When that occurs the static page has a combination of meta-refresh, javascript, and a paragraph with a link to the redirected page to handle all possible scenarios. Unfortunately, this combination poses some issues, such as a blank page being displayed while the redirection is occurring, if the page is slow loading the user will see the paragraph text, and once the redirection is completed, the back-button will not work in IE. To avoid these issues, here are a couple of solutions for handling those redirects, the first is to have ASP.net serve .htm files, the second is to install ISAPI Rewrite version 2 or 3.
Solution One - IIS Mapping and BeginRequest
The first solution involves saving all the static pages that need to be redirected to an application level variable and using Global.asax to handle requests. Here's a basic explanation of a request; The request goes to the Server, IIS determines how to handle the request based upon the path and file name. If it's an htm or html file request, IIS will serve that page itself, if it's an .aspx file, IIS forwards the request to ASP.net. In order for ASP.net to handle htm or html pages, we need to change the mappings for the website. The article How To Enable HTM Server Side Include Parsing in IIS explains how to update mappings for htm and html.
For a more in-depth article on the ASP.NET Application Life cycle, please read this article, ASP.NET Application Life Cycle Overview for IIS 5.0 and 6.0.
Here's an example Global.asax file that saves redirected pages to an application level variable and checks each request to see if it's an .htm static page and if it should be redirected. The two important sub-routines is Application_Start and Application_BeginRequest. Application_Start is called whenever the web site is restarted and Application_BeginRequest is called whenever a request is forwarded from IIS to ASP.net
The final step is to update the example Global.asax file to write to the httpd.ini file with the latest page redirects. In the second version of Global.asax, the new subroutine updateISAPIRedirections() was added and you can optionally remove the Application_BeginRequest() altogether, since ISAPI Rewrite will be handling all incoming requests.
Solution One - IIS Mapping and BeginRequest
The first solution involves saving all the static pages that need to be redirected to an application level variable and using Global.asax to handle requests. Here's a basic explanation of a request; The request goes to the Server, IIS determines how to handle the request based upon the path and file name. If it's an htm or html file request, IIS will serve that page itself, if it's an .aspx file, IIS forwards the request to ASP.net. In order for ASP.net to handle htm or html pages, we need to change the mappings for the website. The article How To Enable HTM Server Side Include Parsing in IIS explains how to update mappings for htm and html.For a more in-depth article on the ASP.NET Application Life cycle, please read this article, ASP.NET Application Life Cycle Overview for IIS 5.0 and 6.0.
Here's an example Global.asax file that saves redirected pages to an application level variable and checks each request to see if it's an .htm static page and if it should be redirected. The two important sub-routines is Application_Start and Application_BeginRequest. Application_Start is called whenever the web site is restarted and Application_BeginRequest is called whenever a request is forwarded from IIS to ASP.net
Pros
You can write code that is tailored for a user's session, so when a request for an htm or html page is made, you can check session variables, such as the user being logged in or not.Cons
Possible performance hit, since ASP.net is now handling .htm or .html pages.Solution Two - ISAPI Rewrite
The other option is to use ISAPI Rewrite 2 or ISAPI Rewrite 3. In this example, I'm using ISAPI Rewrite 2.7. In order to use it, you will need to purchase and install the software on your server. After installing the software, simply create an httpd.ini file in the root directory of your website and add your RewriteRules. It's also important to note that the request process is now slightly different. The ISAPI Rewrite handles all requests first, then the request is forwarded to IIS, which forwards any .aspx requests to ASP.net. You also won't need to update the mappings for htm or html that was done in solution one.httpd.ini example
[ISAPI_Rewrite]
# ISAPI_Rewrite Version 2.7
# RewriteRule ^{request path} {new path} [I,R]
# ^ = Start of url path, excludes the http and the domain
# I = case insensitive
# R = Redirect, code of 302, temporarily moved
# PAGE REDIRECTS START
RewriteRule ^/kens_web_page.htm /kens_place/default.htm [I,R]
RewriteRule ^/kens_web_page.htm /kens_place/default.htm [I,R]
# PAGE REDIRECTS END
The final step is to update the example Global.asax file to write to the httpd.ini file with the latest page redirects. In the second version of Global.asax, the new subroutine updateISAPIRedirections() was added and you can optionally remove the Application_BeginRequest() altogether, since ISAPI Rewrite will be handling all incoming requests.
Pros
Possibly faster than the Global.asax solution and it's easy to use.Cons
Will need to purchase and install ISAPI Rewrite. You can't perform session state checks for a user.
ASP.NET 2.0, From the Workbench
by Ken Foubert | 12/1/2008 8:26am | Comments (2)
by Ken Foubert | 12/1/2008 8:26am | Comments (2)
hi sir
i new in asp.net i m trying to implent this thing in my web site. and for that i have 30 product in my web site which is divided in 3 diff templates. and have individual id. but for calling this through product.aspx?id="1" instead of this i have to hide this is using your techiniques plz help me to solve this issue..
i already read your artical but i dn't get any single refrence. if u have any video related to this plz send me link..
i'll do it...
thhanks in advance
omkar
Left by omkar | Oct 7, 2009
Hi, Ken! I jumped on a thread started by you recently on Helicon's forum, http://www.helicontech.com/forum/forum_posts-TID-13966-TPN-1.htm - I'm trying to do something almost identical to what you were doing, sticking a # in front of the word "artist" instead of "profiles" as in your case. I thought it would be quite straightforward to just copy the solution mentioned in the thread, but boy was I wrong! I can't seem to get ISAPI_Rewrite to catch my URL, and the guy from Helicon who's attempting to answer the thread seems to keep getting off on a tangent, or missing the point - or maybe I am too, but in any case... I thought I'd go to the source: Would you be able to show me what's in your .htaccess file rule contents? And were there any other gotchas that I should be aware of? Any assistance at this point would be greatly appreciated.
Best regards,
Karen Hartley
Left by Karen Hartley | Feb 25, 2010