我想重寫一個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了這個問題,但...我發現的方法,更多或更少,我已經嘗試過。我錯在哪裏?
對此有何建議? 謝謝您提前