我想在一个asp.net网站重写URL如何重写URL在ASP.net网站
我需要的是我不希望用户看到哪种语言的网站创建
即它不应该有www.examplesite.com/index.aspx
作为地址
相反,我希望它为www.examplesite.com/index
我不想让用户看到文件的扩展名
如果此问题与Stackoverflow无关,请将此问题重定向到Stack Exchange的相应站点。
任何帮助表示赞赏。
我想在一个asp.net网站重写URL如何重写URL在ASP.net网站
我需要的是我不希望用户看到哪种语言的网站创建
即它不应该有www.examplesite.com/index.aspx
作为地址
相反,我希望它为www.examplesite.com/index
我不想让用户看到文件的扩展名
如果此问题与Stackoverflow无关,请将此问题重定向到Stack Exchange的相应站点。
任何帮助表示赞赏。
您可以在Global.asax从简单的层面做这个文件是这样的:
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
' Fires at the beginning of each request
Dim path As String = HttpContext.Current.Request.Path
If path.ToLower.EndsWith(".aspx") Then
path = path.Substring(0, path.Length - 5)
Response.Redirect(path, True)
Else
path += ".aspx"
Context.RewritePath(path)
End If
End Sub
如果您有其他文件如.png文件所要求的,您可能需要一些额外的逻辑来过滤掉这些文件。
在web.config文件中,添加以下代码。
<rewrite>
<rules>
<clear />
<rule name="exampleredirect" stopProcessing="true">
<match url="^index.aspx" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="/index" />
</rule>
</rules>
</rewrite>
请参考下面的链接。
http://forums.asp.net/t/1910607.aspx?web+config+rewrite+rule
我收到一个错误无法识别的配置节'重写' –
我已经添加了代码在系统.WebServer'现在我没有收到错误,但仍能看到扩展名。我在LocalHost中检查它 –
您需要安装[URL重写模块](http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module)你的服务器为此工作 – Johan
与你的问题相关的问题是在ASP.Net的URL Rewriting
。对于URL重写有多种方法:在IIS
或使用ASP.NET Web.config
文件写入重写模块。
对于使用web.config
文件,您首先需要在<rewrite > </rewrite>
标记中添加重写配置部分并根据您的要求定义重写规则。
欲了解更多详情:关注此Link。
我希望这会帮助你。
谢谢你的回应。由** [马特威尔科](http://stackoverflow.com/users/500974/matt-wilko)**提供的解决方案是最简单和容易的一个..!所以我已经标记他的答案,我已经upvoted你的 –
有一个NuGet包为了这个,我认为,其所谓的Friendly Urls
谢谢你的回应..!由[马特威尔科](http://stackoverflow.com/users/500974/matt-wilko)提供的解决方案是最简单和容易的.. ..!谢谢你让我知道Fiendly网址..! :) –
在你需要添加一个节在web.config称为<rewrite> </rewrite>
,那么你将添加的规则/规则的名称,因为我已经做了如下:
<rewrite><rules><clear />
<rule name="redirectrule" stopProcessing="true">
<match url="^index.aspx" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false" />
<action type="Redirect" url="/index" />
</rule></rules></rewrite>
谢谢你的回应。由[马特威尔科](http://stackoverflow.com/users/500974/matt-wilko)提供的解决方案是最简单和容易的.. ..! –
这就是所谓URL重写,而不是部署。 – CodeCaster
可能重复的[IIS URL重写](http://stackoverflow.com/questions/1089183/iis-url-rewrite) – CodeCaster