开发者

ASP.net help rewriting simple URL

<rewrite url="~/Blog" to="~/Blog.aspx" processing="stop"/>

This doesn't work, it only seems to work if I define a replacement filename as well... How do I make it so that

ht开发者_如何学编程tp://www.mysite.com/Blog

Goes to:

http://www.mysite.com/Blog.aspx


See Scott Guthrie's Post


With IIS 6.0 (Windows XP and Windows Server 2003), you can't do this with the usual configuration. IIS looks for a file extension to route the URL to determine which of the installed engines (classic ASP, ASP.Net, PHP, etc.) the request should get routed to. When there's no extension, IIS looks in the corresponding folder (virtual or real) for a default document, like default.aspx or index.htm, etc.

With IIS 7, you can use Integrated mode to get the behavior you want. With IIS 6, you can still do it by specially configuring it to route all URLs to ASP.Net, regardless of extension. For efficiency, you may want to refine it so that static files like images are not routed to ASP.Net. How to do this is explained here: http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/5c5ae5e0-f4f9-44b0-a743-f4c3a5ff68ec.mspx?mfr=true


Consider using MVC routing. If you're using .NET 4 it's even easier. All you have to do is reference System.Web.Routing and then in the global.asax file you can do routes.MapPageRoute("Blog Route", "Blog", "~/Blog.aspx");

Helpful references:

  • http://msdn.microsoft.com/en-us/library/cc668201.aspx (.net 4)

  • https://web.archive.org/web/20211020111718/https://www.4guysfromrolla.com/articles/012710-1.aspx (.net 4)

  • https://web.archive.org/web/20201205221404/https://www.4guysfromrolla.com/articles/051309-1.aspx (.net 3.5)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜