我想重写一个url以匹配页面文件名的确切名称。 我的意思是:我有一个http://example.com/PagePage.aspx,并在浏览器栏上打字http://example.com/pagepage.aspx我想再次获得http://example.com/PagePage.aspx。在web.config中重写URL c#
当然,上键入字符的任意组合,即Pagepage.aspx,pagePage.aspx相同,等等...
我试过这样:
<system.webServer>
<rewrite>
<rules>
<rule name="SpecificRewrite" stopProcessing="true">
<match url="^pagepage$" />
<match url="^Pagepage$" />
<match url="^pagePage$" />
<action type="Rewrite" url="PagePage.aspx" />
</rule>
</rules>
</rewrite>
</system.webServer>
,但我得到“500 - 内部服务器错误”。
所以我也试过这样:
<system.webServer>
<rewrite>
<rules>
<rule name="SpecificRewrite" stopProcessing="true">
<match url="^pagepage\/?$" />
<match url="^Pagepage\/?$" />
<match url="^pagePage\/?$" />
<action type="Redirect" url="/PagePage.aspx" />
</rule>
</rules>
</rewrite>
</system.webServer>
,但我得到一个无限循环
我尝试使用的Global.asax
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
string path = context.Request.Path;
if (path.Equals("/pagepage.aspx"))
{
context.RewritePath(path.Replace("pagepage.aspx", "PagePage.aspx"));
// or context.RewritePath("PagePage.aspx"); is the same
}
}
但要获得同样的,一次。 ..我得到一个无限循环错误...
我GOOGLE了这个问题,但...我发现的方法,更多或更少,我已经尝试过。我错在哪里?
对此有何建议? 谢谢您提前