urlrewriter的使用

开源类库地址 https://github.com/sethyates/urlrewriter/find/master

  1 <?xml version="1.0"?>  
  2 <configuration>  
  3     <configSections>  
  4         <section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter"/>  
  5         <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">  
  6             <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">  
  7                 <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>  
  8                 <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">  
  9                     <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>  
 10                     <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>  
 11                     <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>  
 12                     <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>  
 13                 </sectionGroup>  
 14             </sectionGroup>  
 15         </sectionGroup>  
 16     </configSections>  
 17     <appSettings/>  
 18     <connectionStrings/>  
 19     <system.web>  
 20         <!--   
 21             Set compilation debug="true" to insert debugging   
 22             symbols into the compiled page. Because this   
 23             affects performance, set this value to true only   
 24             during development.  
 25         -->  
 26         <compilation debug="true">  
 27             <assemblies>  
 28                 <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>  
 29                 <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>  
 30                 <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
 31                 <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>  
 32             </assemblies>  
 33         </compilation>  
 34         <!--  
 35             The <authentication> section enables configuration   
 36             of the security authentication mode used by   
 37             ASP.NET to identify an incoming user.   
 38         -->  
 39         <authentication mode="Windows"/>  
 40         <!--  
 41             The <customErrors> section enables configuration   
 42             of what to do if/when an unhandled error occurs   
 43             during the execution of a request. Specifically,   
 44             it enables developers to configure html error pages   
 45             to be displayed in place of a error stack trace.  
 46   
 47         <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">  
 48             <error statusCode="403" redirect="NoAccess.htm" />  
 49             <error statusCode="404" redirect="FileNotFound.htm" />  
 50         </customErrors>  
 51         -->  
 52         <pages>  
 53             <controls>  
 54                 <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
 55                 <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
 56             </controls>  
 57         </pages>  
 58         <httpHandlers>  
 59             <remove verb="*" path="*.asmx"/>  
 60             <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
 61             <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
 62             <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>  
 63         </httpHandlers>  
 64         <httpModules>  
 65             <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
 66             <add type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" name="UrlRewriter"/>  
 67         </httpModules>  
 68     </system.web>  
 69     <rewriter> 70 <rewrite url="/tags/(.+)/(.+)" to="/tagcloud.aspx?tag=$1&amp;date=$1"/> 71 </rewriter>  
 72     <system.codedom>  
 73         <compilers>  
 74             <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">  
 75                 <providerOption name="CompilerVersion" value="v3.5"/>  
 76                 <providerOption name="WarnAsError" value="false"/>  
 77             </compiler>  
 78         </compilers>  
 79     </system.codedom>  
 80     <!--   
 81         The system.webServer section is required for running ASP.NET AJAX under Internet  
 82         Information Services 7.0.  It is not necessary for previous version of IIS.  
 83     -->  
 84     <system.webServer>  
 85         <validation validateIntegratedModeConfiguration="false"/>  
 86         <modules>  
 87             <remove name="ScriptModule"/>  
 88             <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
 89         </modules>  
 90         <handlers>  
 91             <remove name="WebServiceHandlerFactory-Integrated"/>  
 92             <remove name="ScriptHandlerFactory"/>  
 93             <remove name="ScriptHandlerFactoryAppServices"/>  
 94             <remove name="ScriptResource"/>  
 95             <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
 96             <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
 97             <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
 98         </handlers>  
 99     </system.webServer>  
100     <runtime>  
101         <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">  
102             <dependentAssembly>  
103                 <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>  
104                 <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>  
105             </dependentAssembly>  
106             <dependentAssembly>  
107                 <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>  
108                 <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>  
109             </dependentAssembly>  
110         </assemblyBinding>  
111     </runtime>  
112 </configuration>  

第4,66,69~71 行为需要配置的内容

 

发布到IIS服务器后

 

如果是IIS6.0 需要添加通配符 

操作步骤如下

IIS站点属性 ->主目录 ->  配置  -> 插入通配符
选择或输入

c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll

取消"确认文件是否存在"前的钩. 
确定 

 

如果是IIS7,则在需要添加新的web.config元素

1. 在modules 结点添加runAllManagedModulesForAllRequests属性

<modules runAllManagedModulesForAllRequests="true">

2. 在modules结果添加以下配置

  <!--您的自定义IIS重写模块操作-->
       <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule"/>

 

你可能感兴趣的:(urlrewrite)