zoukankan      html  css  js  c++  java
  • 页面伪静态

    mvc可以直接配置路由,虽然aspx已经是过去式,但是学习一下也是有必要的。

    1、直接在global.ashax中Application_BeginRequest方法中讲url重写

          protected void Application_BeginRequest(object sender, EventArgs e)
            {
                var path = Request.AppRelativeCurrentExecutionFilePath;
                Regex regex = new Regex(@"~/default-(d+)");
                if (regex.IsMatch(path))
                {
                    var realPath = regex.Replace(path, @"~/default.aspx?a=$1");
                    Context.RewritePath(realPath);
                }
    
            }

    2、写一个Module,然后在webconfig中配置启动。

    public class URLRewriterModule : IHttpModule
        {
            public void Init(HttpApplication context)
            {
                context.BeginRequest += (s, e) =>
                    {
                        HttpApplication app = s as HttpApplication;
                        var path = app.Context.Request.AppRelativeCurrentExecutionFilePath;
    
                        Regex regex = new Regex(@"~/default-(d+)");
                        if (regex.IsMatch(path))
                        {
                            var realPath = regex.Replace(path, @"~/default.aspx?a=$1");
                            app.Context.RewritePath(realPath);
                        }
    
                    };
    
            }
    
            public void Dispose()
            { }

    webconfig中system.webServer的节点下配置

      <system.webServer>
        <!--设置不去校验过时配置-->
        <!--<validation validateIntegratedModeConfiguration="false"/>-->
        
        <modules>
          <!---namez自定义随便写,type写完整路径名称和网站程序集名称-->
          <add name="myurlrewriter" type="UrlRewriterForm.URLRewriterModule,UrlRewriterForm"/>
        </modules>
        <defaultDocument>
          <files>
            <!--<add value="index.aspx"/>-->
          </files>
        </defaultDocument>
      </system.webServer>

    如果是老版本iis,是在system.web的节点配置

     <httpModules>
          <!--老版本iis使用-->
          <add name="myurlrewriter" type="UrlRewriterForm.URLRewriterModule,UrlRewriterForm"/>
        </httpModules>

    并且在system.webServer下配置

      <!--设置不去校验过时配置-->
        <validation validateIntegratedModeConfiguration="false"/>

    3、使用第三方的URLRewriter,可以用NuGet获取包,原理应该和2是一样的,只不过将url重写规则放在配置中,然后module中读取配置信息。安装完包之后webconfig中自动增加了一些信息:

      <configSections>
        <section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
      </configSections>
      <httpModules>         
          <add type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" name="UrlRewriter" />      
        </httpModules>

    system.webServer下面出现rewriter

    <rewriter>
        <redirect url="~/Default.aspx" to="~/Default" />
        <redirect url="~/Login.aspx" to="~/Login" />
      </rewriter>

    HTTP 错误 500.22 - Internal Server Error
    检测到在集成的托管管道模式下不适用的 ASP.NET 设置。

    将配置迁移到 system.webServer/modules 节。
    如果您确信可以忽略此错误,则可以通过将 system.webServer/validation@validateIntegratedModeConfiguration 设置为 false 来禁用它。

      <system.webServer>
        <!--设置不去校验过时配置-->
        <validation validateIntegratedModeConfiguration="false"/>
        <modules>    
          <add type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" name="UrlRewriter" />
        </modules>
        <defaultDocument>
          <files>
            <!--<add value="index.aspx"/>-->
          </files>
        </defaultDocument>
      </system.webServer>

    4、用第三方插件直接在iis服务器上修改。

    isapi_rewrite

    http://www.helicontech.com/isapi_rewrite/download.html

    Free URL Rewriter

    http://www.microsoft.com/web/spotlight/urlrewriter/

  • 相关阅读:
    tomcat 部署项目的多种方式
    HttpServletRequestWrapper模拟实现分布式Session
    eclipse4.3 解决没有check out as maven project
    Mysql的Merge存储引擎实现分表查询
    ubuntu gcc低版本过低引起错误
    SpringMVC强大的数据绑定
    Reading Notes : 180212 冯诺依曼计算机
    Reading Notes : 180211 概述计算机
    Struts2 第六讲 -- Struts2的结果类型
    Struts2 第五讲 -- Struts2与Servlet的API解耦
  • 原文地址:https://www.cnblogs.com/tgdjw/p/4616002.html
Copyright © 2011-2022 走看看