Intelligencia. urlrewriter cannot find Error 404 on this page

Source: Internet
Author: User

Reference: How to Do URL rewrites with ASP. NET 2.0 3.0 3.5 on IIS6 and iis7 and what is wild card Mapping

Http://peterkellner.net/2008/08/24/urlrewrite-with-aspnet-urlrewriter-wildcard-mapping-iis6-iis7/

 

The key is to remove the check mark before "whether to search for a file exists ".

 

In the iis5.1 environment of XP, Set

Installing urlrewriter. Net on Windows XP

Although you can use urlrewriter. net without making any changes to your IIS configuration, you will have a few limitations in the sorts of friendly URLs you can use. in particle, the URL must be mapped to the ASP. net runtime in order for urlrewriter. net to rewrite it. to get the full power of urlrewriter. net, configure IIS 5.0 to map all requests to the ASP. net runtime.

Refreshing ing IIS 5.0 on Windows Server XP to enableUrlrewriter. netIs easy because IIS 5.0 supports wildcard application mappings. this setting enables IIS to map all unrecognised application requests to (in our instance) the ASP. net runtime. to enable this wildcard mapping which will enable the urlrewriter. NET component to work, follow these simple steps on each web server where urlrewriter. net will be running (even you developer desktop ).

    1. Open up IIS and navigate to the "Home Directory tab"
    2. Select "configuration"
    3. Click "add" and enter "C: \ WINDOWS \ Microsoft. net \ framework \ v2.0.50727 \ aspnet_isapi.dll "in the executable box. for the file extension, enter ". *". finally, make sure that "check that file exists" is not checked.

 

Body reference:

The Problem

Over the past several years I 've found myself running into the same problem over and over so I thought I 'd blog the solution so at least I don't waste time figuring it out again. so, when do you need this? The answer for me is that I want to be able reference a web site without having to expose the underlying site structure. for example, on the home page of my business, I want people to be able to type http://73rdstreet.com/Home and be taken to http://www.73rdstreet.com/HomeSite/Home.aspx.

 

The symptom

You may see errors that say something like:

Server Error in application... HTTP Error 404.0-not found

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Maprequesthandler staticfile

And the screen may show something like this.

If this happens, read on.

 

Theory

The first thing to understand is that IIS by default will pass to the Asp.net process only the requests that have a certain file extension. that is, aspx, ashx, etc. basically, only file extensions that have a handler defined for them to be processed. other URL's that don't meet the criteria are not passed to IIS. this operation des no file extension at all. there is a good reason for this. one, it makes processing of things like images (JPG's, GIF's, etc .) faster because they do not every have to be processed through the Asp.net worker process. secondly, it lowers the exposure of the Asp.net worker process so that it is less likely to be compromised.

So, the first thing that has to be done is to tell IIS to pass all requests through using something called wild card mapping. then, once this is done, the request comes through to the Asp.net worker process regardless of what it is. as we know, the place that we wowould have to process this is an httpmodule. the reason is that since it's not a page yet, we have no idea what to do with it. basically modules let you tap into the request at different stages. to do the rewrite from .. /home .. /homesite/home. aspx we want to tap into the application_beginrequest event. the context. rewritepath method is called at that point to force a new path based on what we want (hopefully not hard coded ).

After the rewritepath is set, the page is processed as if is going to the correct page.

 

How to Set wild card mapping in IIS6

To set wild care mapping in IIS6 you need to do the following.

Run inetmgr and navigate to the properties page of the website you want to set.

Then, from the properties page, click the configuration button as shown below.

Then, press the insert button on the configuration screen and see the following screen and then click on the insert button.

Now, insert your Asp.net isapi dll. on my system, the file is here: C: \ WINDOWS \ Microsoft. net \ framework \ v2.0.50727 \ aspnet_isapi.dll. make sure to uncheck the box "verify that file exists ".

That's it! Now, all requests will be processed through you Asp.net pipeline so you will be able to intercept anything on the URL you want. Be careful though, you may get more than you ask!

How to Set wildcard mapping in iis7

In iis7 things are a little different. First thing you need to do is unlock the config section "handlers". You do this by bring up a DOS prompt and entering the command:

C: \ windows \ system32 \ inetsrv> appcmd.exe unlock config/section: system. webserver/handlers

Then, you can set your wildcard handler in your web. config file as follows.

Now, the default handlers will be executed in your web. config file, and of course, all the defaults for that are in the chain of files that inherits from. for more details on that, see this FAQ: configuration files FAQs (web. config, machine. config ...).

You may need to add the wildcard mapper handler to your web. config. To do this, you wocould put the following in your web. config

 <?  XML  Version  = "1.0"   Encoding  = "UTF-8" ? > 
< Configuration >
< System. Webserver >
< Handlers >
< Add Name = "Wildcard" Path = "*" Verb = "*" Type = "Sampletype" Resourcetype = "Unspecified" />
</ Handlers >
</ System. Webserver >
</ Configuration >

Now, you shoshould be set. See the next section for a good method for actually doing the remapping, which is why we went down this path in the first place.

 

Implementing a URL rewriter for mapping.../home to.../homesite/home. aspx

So, as discussed in the theory section above, you cocould write your own code to map What You Want To where you want it. you cocould put in your global. asax some code for the application_beginrequest and make a big case statement for everything you want to do. well, as we know, that wocould give your code a bad smell and we don't want that because soon, you will find yourself using cut and paste and other problematic crutches.

So, to avoid all that, and do what Scott Guthrie suggests, use the open source package urlrewriter. net. it's light-weight and retriable through a small section in your web. config. before putting in the what to do, here are the steps to make urlrewriter work in a very simple way (the way I use it on my company home page.

In your <system. Web> of your web. config place a definition for a new config section where you will put your rewrites

<Configuration>
 
<Configsections>
 
<Section Name= "Rewriter" Requirepermission= "False" 
 
Type= "Intelligencia. urlrewriter. configuration. rewriterconfigurationsectionhandler, intelligencia. urlrewriter"/>

 

Then, put the module that actually does the work of the rewrite as described in the theory section above

 
<System. Web>
 
<Httpmodules>
 
<Add name ="Urlrewriter" 
Type ="Intelligencia. urlrewriter. rewriterhttpmodule, intelligencia. urlrewriter"/>
 
</Httpmodules>
 
..

Then, further down in your web. config put

<System. Webserver>
 
<Validation Validateintegratedmodeconfiguration= "False"/>
 
<Modules>
 
<Add name = "urlrewriter"
 
Type = "intelligencia. u
And, finally to actually do the redirect you need to put a new <rewriter> tag with a list of redirects in it.
 
<Rewriter>
<Rewrite URL= "~ /Home" To= "~ /Pages/home. aspx"/>
 
</Rewriter>

 

That's it! You are done. Hope this helps, or at least helps me the next time I'm searching for the same problem (for the 4th time at least ).

 

References:

Http://devtalk.dk/2007/03/19/Wildcard+Mapping+And+URL+Rewriting+On+IIS7.aspx

Http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

Http://urlrewriter.net/

Http://forums.asp.net/t/1240344.aspx

Http://professionalaspnet.com/archive/2007/07/27/Configure-IIS-for-Wildcard-Extensions-in-ASP.NET.aspx

Http://professionalaspnet.com/archive/2007/07/27/Create-an-HttpModule-to-Process-Wildcard-Extension-Mapping-in-ASP.NET.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.