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

  • 相关阅读:
    python读取配置文件
    日志截取
    QJsonObject
    OpenStack
    生成器迭代器正则视频笔记
    使用Qt.createComponent 动态加载组件
    linux 远程执行命令
    Django 建立工程连接数据库
    arm基础1
    QSetting的用法
  • 原文地址:https://www.cnblogs.com/wifi/p/2269983.html
Copyright © 2011-2022 走看看