把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);
    }
}
这样就可以在浏览器地址栏里用http://localhost/1234/xxx.html 来访问你的 http://localhost/1234/xxx.aspx页面了,浏览器地址栏显示的是http://localhost/1234/xxx.html (页面带参数也是可以的)。

posted on 2011-10-19 09:39  大豆男生  阅读(1267)  评论(17编辑  收藏  举报

导航