zoukankan      html  css  js  c++  java
  • 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 从而实现伪静态………………………………………………

    页面显示:


    学无先后,达者为师
  • 相关阅读:
    CDN网络(二)之配置和优化CDN核心缓存软件--squid
    CDN网络(一)之典型的CND架构与HTTP协议的缓存控制
    http+mysql结合keepalived做热备
    网络存储(四)之ISCSI的进阶
    Nginx系列3之Nginx+tomcat
    Nginx系列2之Nginx+php
    Nginx系列1之部分模块详解
    网络存储(三)之ISCSI搭建的入门
    网络存储(二)之ISCSI原理
    Testing
  • 原文地址:https://www.cnblogs.com/seanchang/p/5202746.html
Copyright © 2011-2022 走看看