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

Aggie ·
更新时间:2024-09-21
· 629 次阅读

在 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(页面带参数也是可以的)。 您可能感兴趣的文章:aspx文件格式使用URLRewriter实现静态化变成html将.aspx转换为.htm的两种方法



aspx HTML

需要 登录 后方可回复, 如果你还没有账号请 注册新账号