zoukankan      html  css  js  c++  java
  • 把aspx页面伪装成html

    在 Global.asax.cs 中添加 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 (页面带参数也是可以的)。

    后台Global.asax.cs代码:

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Web;
    using System.Web.Security;
    using System.Web.SessionState;
    namespace TestApp1
    {
    public class Global : System.Web.HttpApplication
    {
    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);
    }
    }
    }
    }

    前台Global.asax 代码:

    <%@ Application Codebehind="Global.asax.cs" Inherits="TestApp1.Global" Language="C#" %>


    关于vs2005中 Global.asax 没有 Global.asax.cs 问题解决 方法见:http://www.cnblogs.com/wifi/archive/2011/12/01/2269969.html

  • 相关阅读:
    高中信息技术《算法与程序设计VB(选修)》知识要点
    信息技术选修一总结
    文学给人以相爱的力量
    雾霾
    杯子
    递归
    死锁
    高精度计算练习1
    高精度加法的优化
    字符串函数与过程
  • 原文地址:https://www.cnblogs.com/wifi/p/2269983.html
Copyright © 2011-2022 走看看