6

I'm trying to enable rewrited urls in my project. it's very good described in this post: urlrewriting by scottgu It works very well when im running it on localhost, but as soon as i upload it to my host (.net 3.5), it doesn't work! i always get redirected to a 404 page!

Is there a configuration needed to enable this? as scottgu says no, but i don't find out why it's not working...

thanks

// UPDATE 2.09.2010

Is there actually a way to enable routing or rewriting without having iis7 or the ability to install a modul like ISAPI Rewrite on the server? Looks like i got a bad asp.net host...

k0ni
  • 2,417
  • 4
  • 22
  • 25
  • Have you tried to see how your url is rewrited in Application_BeginRequest? – mamoo Aug 30 '10 at 09:01
  • 1
    what is the version of your IIS? – Adeel Aug 30 '10 at 09:04
  • how can i see this? im using this method: void Application_BeginRequest(object sender, EventArgs e) { string fullOrigionalpath = Request.Url.ToString(); if (fullOrigionalpath.Contains("/Products/Books.aspx")) { Context.RewritePath("/Products.aspx?Category=Books"); } .... } – k0ni Aug 30 '10 at 09:05

3 Answers3

4

In your localhost environment you are probably running the website on your ASP.NET Development server. That server is set up to capture all request (* . *) and run them through the ASP.NET pipeline.

II6 on the other hand, is configured to only send some requests ( ie *.aspx, *.asmx, *.ashx) through the ASP.NET pipeline. So if you are trying to catch a request for an url like "/my/fine/url" that will never be passed to the ASP.NET handler, and thus not rewritten.

You can change this configuration in the Application configuration for the website:

  1. Open IIS Manager and right-click on the website, choose Properties
  2. On the tab "Home Directory", click "Configuration..." button.
  3. Click "Insert..." button to insert a Wildcard application map.
  4. In "Executable:" insert path to aspnet_isapi.dll, in my case C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll (note: this path may differ on you server).
  5. Remember to uncheck "Verify that file Exists"
  6. Click OK!

And so! All your requests should now be directed to the ASP.NET handler and hence caught in your URL rewriter, regardless of extension.

But I must admit that I'm a bit unsure as to how this will affect performance on you site, routing all requests for static files, css, images etc through the ASP.NET handler. Maybe someone else out there has something to say about that.

/Dennis :-)

Dennis Skantz
  • 363
  • 2
  • 8
  • but i would be interested in how this affects performance and other things...is this the right way to do it? thx – k0ni Aug 31 '10 at 07:59
  • Thats the way to run ASP.NET MVC on IIS6 but all requests even for static content are going through ASP.NET pipeline and performance suffers. You can use mscd.codeplex.com to avoid this. – dariol Aug 31 '10 at 13:46
  • Yep the throughput for static requests will be reduced by ~30%. The best way to avoid this is to partition your site : create two web sites, one with your wildcard mapping without any static resources, and another with your static resources only without a wildcard mapping. Furthermore, its a good pratice with or without a wildcard mapping ;) – JoeBilly Sep 07 '10 at 10:21
1

There are two ways to get the extensionless routes in IIS6:

a) ISAPI rewrite or other ISAPI url rewriter
b) Use a wildcard mapping to aspnet_isapi.dll

See this blog post for detailed instructions.

Wyatt Barnett
  • 15,573
  • 3
  • 34
  • 53
0

Here is example how to use new System.Web.Routing within ASP.NET WebForms.

http://deepumi.wordpress.com/2010/02/27/url-routing-in-asp-net-web-forms/

dariol
  • 1,959
  • 17
  • 26