把aspx頁面?zhèn)窝b成靜態(tài)html格式的實現(xiàn)代碼
更新時間:2011年10月19日 23:01:41 作者:
把aspx頁面?zhèn)窝b成靜態(tài)html格式的實現(xiàn)代碼,主要是利于搜索引擎的收錄。
在 Global.asax 中添加 Application_BeginRequest 事件:
protected void Application_BeginRequest(object sender, EventArgs e)
{
string pathAndQuery = Request.Url.PathAndQuery.ToLower();
if (pathAndQuery.IndexOf(".html") > -1)
{
pathAndQuery = "~/" + pathAndQuery.Replace(".html", ".aspx");
HttpContext.Current.RewritePath(pathAndQuery);
}
}
這樣就可以用xxx.html 來訪問你的 xxx.aspx頁面了,瀏覽器地址欄顯示的是xxx.html(頁面帶參數(shù)也是可以的)。
復制代碼 代碼如下:
protected void Application_BeginRequest(object sender, EventArgs e)
{
string pathAndQuery = Request.Url.PathAndQuery.ToLower();
if (pathAndQuery.IndexOf(".html") > -1)
{
pathAndQuery = "~/" + pathAndQuery.Replace(".html", ".aspx");
HttpContext.Current.RewritePath(pathAndQuery);
}
}
這樣就可以用xxx.html 來訪問你的 xxx.aspx頁面了,瀏覽器地址欄顯示的是xxx.html(頁面帶參數(shù)也是可以的)。
相關文章
解析.netcore項目中IStartupFilter使用教程
netcore項目中有些服務是在通過中間件來通信的,比如orleans組件,今天通過實例代碼給大家介紹下netcore項目中IStartupFilter使用教程,感興趣的朋友一起看看吧2021-11-11ASP.NET技巧:數(shù)據(jù)島出到Excel最為簡易的方法
ASP.NET技巧:數(shù)據(jù)島出到Excel最為簡易的方法...2006-09-09如何給ASP.NET Core Web發(fā)布包做減法詳解
在ASP.Net中可以使用打包與壓縮這兩種技術來提高Web應用程序頁面加載的性能。下面這篇文章主要給大家介紹了關于如何給ASP.NET Core Web發(fā)布包做減法的相關資料,需要的朋友可以參考借鑒,下面來一起看看吧2018-06-06