开发者

Rewrite Application Path ASP.NET C#

How would I go about rewriting /path/default.aspx?i=ID to /path/ID/ without开发者_StackOverflow中文版 the ?i= part of the query url?


You can do this with an http module in asp.net 1.1/2.0:

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

ASP.NET 4.0 adds support for URL rewriting natively (it was added as part of 3.5 SP1 but only for ASP.NET MVC, now it's being made available for all ASP.NET apps).

http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx


You have several options.

  1. You can use ASP.NET MVC's routing with WebForms if you are in a 3.5 or later environment. I like the straightforward nature of ASP.NET MVC's routing. It's pretty easy to understand and can be unit tested.
  2. You can use ISAPI ReWrite if you are in a 2.0 or later environment. ISAPI Rewrite is RegEx based, and I find it a little tougher to understand than MVC's routing mechanism. Your setup cannot be be unit tested because as the name suggests, it works at the ISAPI.DLL level.
  3. Or, you can do as Sam suggested in use the native stuff with WebForms in ASP.NET 4.0.
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜