把aspx页面伪装成静态html格式的实现代码
更新时间:2011年10月19日 23:01:41 作者:
把aspx页面伪装成静态html格式的实现代码,主要是利于搜索引擎的收录。
在 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(页面带参数也是可以的)。
复制代码 代码如下:
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(页面带参数也是可以的)。
相关文章
解析.netcore项目中IStartupFilter使用教程
netcore项目中有些服务是在通过中间件来通信的,比如orleans组件,今天通过实例代码给大家介绍下netcore项目中IStartupFilter使用教程,感兴趣的朋友一起看看吧2021-11-11
最新评论