欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-03-07 17:25:03
在 global.asax 中添加 application_beginrequest 事件: 复制代码 代码如下: protected void application_b...
在 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(页面带参数也是可以的)。