• UrlRewrite伪静态



    1.首先添加URLRewriter.dll、ActionlessForm.dll加到bin文件夹中,添加引用

     注:URLRewriter.dll实现伪静态  ActionlessForm.dll是分页时起作用,如果不使用该控件仍会跳转到aspx页面

    ActionlessForm.dll使用方法:在每个aspx页面添加<%@ Register TagPrefix="skm" Namespace="ActionlessForm" Assembly="ActionlessForm" %>

     然后,将 <form runat="server">****</form>替换为: <skm:Form id="Form1" method="post" runat="server">*****</skm:Form>

    2.按如下(红色部分)操作修改配置文件

    <?xml version="1.0"?>
    <configuration>
      <configSections>
        <!--URLRewriter_1 URL开始-->
        <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler,URLRewriter"/>
        <!--URLRewriter_1 URL结束-->

      </configSections>
      <appSettings/>
      <connectionStrings/>
      <!--URLRewriter_2 URL重写开始-->
      <RewriterConfig>
        <Rules>
          <RewriterRule>
            <LookFor>~/(w*)_(w*).html</LookFor>
            <SendTo><![CDATA[~/WebForm1.aspx?ID=$1&Page=$2]]></SendTo>
           
          </RewriterRule>
          <RewriterRule>
            <LookFor>~/index.html</LookFor>
            <SendTo>~/Default.aspx</SendTo>
          </RewriterRule>
          <RewriterRule>
            <LookFor>~/(w*).html</LookFor>
            <SendTo>~/WebForm1.aspx?ID=$1</SendTo>
          </RewriterRule>
        </Rules>
      </RewriterConfig>
      <!--URLRewriter_2 URL重写结束-->

      <system.web>
        <compilation debug="true" targetFramework="4.0">
        </compilation>
        <authentication mode="Windows"/>
        <httpModules>
          <!--URLRewriter_3开始-->
          <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter"/>
          <!--URLRewriter_3结束-->

        </httpModules>
        <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
      </system.web>
      <!--
            在 Internet 信息服务 7.0 下运行 ASP.NET AJAX 需要 system.webServer
            节。对早期版本的 IIS 来说则不需要此节。
        -->
      <system.webServer>
        <handlers>
          <remove name="html"/>
          <add name="html" path="*.html" verb="*" modules="IsapiModule" scriptProcessor="%windir%Microsoft.NETFrameworkv2.0.50727aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32"/>
        </handlers>
      </system.webServer>
    </configuration>

    
    

    3.程序中转向时调用<LookFor></LookFor>节点中配置的URL,注意参数

    4.在iis中添加LookFor 节点配置的后缀

    按照*aspx的配置添加映射(此例添加html映射)


    付代码:

    Default.aspx.cs:

            protected void Page_Load(object sender, EventArgs e)
            {
                RedirectUrl();
            }

            protected void RedirectUrl()
            {
                Response.Redirect("sean_chang.html");
            }

    WebForm1.aspx.cs

                if (!IsPostBack)
                {
                    Response.Write("实际调用WebForm1.aspx页面,参数ID="+ Request.QueryString["ID"]);

                    Response.Write("<script type='text/javascript'>alert('参数page=" + Request.QueryString["Page"] + "')</script>");
                }

    Default页面跳转到sean_chang.html页面 实际上访问的是WebForm1.aspx页面 ,并且根据webconfig配置可知 

    实际访问的url路径为WebForm1.aspx?ID=sean&Page=chang 从而实现伪静态………………………………………………

    页面显示:


    学无先后,达者为师
  • 相关阅读:
    Windows驱动开发-设备读写方式
    Windows驱动开发-r3和r0通信
    Windows驱动开发-内核常用内存函数
    Windows驱动开发-DeviceIoControl函数参数dwIoControlCode
    Windows驱动开发-派遣函数格式
    Windows驱动开发-符号链接和设备名
    windows驱动不要签名
    git使用问题二删除远程仓库文件,本地保留不动
    git使用问题一新建本地仓库添加远程合并推送
    秦汉
  • 原文地址:https://www.cnblogs.com/seanchang/p/5202746.html
Copyright © 2020-2023  润新知