简体   繁体   English

ASP.NET URL 重写

[英]ASP.NET URL Rewriting

How do I rewrite a URL in ASP.NET?如何在 ASP.NET 中重写 URL?

I would like users to be able to go to我希望用户能够访问

http://www.website.com/users/smith

instead of代替

http://www.website.com/?user=smith

Try the Managed Fusion Url Rewriter and Reverse Proxy:尝试托管 Fusion Url 重写器和反向代理:

http://urlrewriter.codeplex.com http://urlrewriter.codeplex.com

The rule for rewriting this would be:重写它的规则是:

# clean up old rules and forward to new URL
RewriteRule ^/?user=(.*)  /users/$1 [NC,R=301]

# rewrite the rule internally
RewriteRule ^/users/(.*)  /?user=$1 [NC,L]

Microsoft now ships an official URL Rewriting Module for IIS: http://www.iis.net/download/urlrewrite微软现在为 IIS 提供了一个官方的 URL 重写模块: http : //www.iis.net/download/urlrewrite

It supports most types of rewriting including setting server variables and wildcards.它支持大多数类型的重写,包括设置服务器变量和通配符。

It also will exist on all Azure web instances out of the box.它也将立即存在于所有 Azure Web 实例中。

I have used an httpmodule for url rewriting from www.urlrewriting.net with great success (albeit I believe a much earlier, simpler version)我使用 httpmodule 从www.urlrewriting.net重写 url 并取得了巨大成功(尽管我相信这是一个更早、更简单的版本)

If you have very few actual rewriting rules then url mappings built in to .NET 2.0 are probably an easier option, there are a few write ups of these on the web, the 4guysfromrolla one seems fairly exhaustive but as you can see they don't support regular expression mappings are are as such rendered fairly useless in a dynamic environment (assuming "smith" in your example is not a special case then these would be of no use)如果您的实际重写规则很少,那么 .NET 2.0 中内置的 url 映射可能是一个更简单的选择,网上有一些关于这些的文章, 4guysfromrolla似乎相当详尽,但正如您所见,它们没有支持正则表达式映射因此在动态环境中变得相当无用(假设您的示例中的“史密斯”不是特例,那么这些将毫无用处)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM