服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服务器之家 - 编程语言 - ASP.NET教程 - 把aspx页面伪装成静态html格式的实现代码

把aspx页面伪装成静态html格式的实现代码

2019-09-20 14:06asp.net教程网 ASP.NET教程

把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(页面带参数也是可以的)。

延伸 · 阅读

精彩推荐