简体   繁体   中英

Removing the .aspx extension from the web application

I am new to URLRewriting and trying to remove the .aspx extension using the following script in my web.config

<configuration>
  <configSections>
     <section name="rewriteModule" type="RewriteModule.RewriteModuleSectionHandler, RewriteModule"/>
  </configSections>
 <connectionStrings>

<system.webServer>
    <rewrite>
      <rules>
           <rule name="Redirect to clean URL" stopProcessing="true">
          <match url="^([a-z0-9/]+).aspx$" ignoreCase="true"/>
          <action type="Redirect" url="{R:1}"/>
          </rule>
     </rules>
    </rewrite>
</system.webServer>

However, I have no success with this. Moreover, the following code block is giving me an error.

 <httpHandlers>
       <add verb="*" path="*.aspx" 
            type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
 </httpHandlers>

> Could not load file or assembly 'URLRewriter' or one of its
> dependencies. The system cannot find the file specified.

Do I need to add the rewrite engine to my web application?

I have gone through this link but I could not get it.

Can any one suggest to me a step by step process or sample script please?

Use the following rule, works like a charm everytime!

<rule name="san aspx">
  <!--Removes the .aspx extension for all pages.-->
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAll">
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  </conditions>
  <action type="Rewrite" url="{R:1}.aspx" />
</rule> 

Seems like you have not added the dll Reference in the Web project for the class URLRewriter. Add this reference to fix this issue.

(As alternatives to writing your own)

IIS 7 URL rewrite module :

http://www.microsoft.com/en-gb/download/details.aspx?id=7435

IIS 5/6 :

http://iirf.codeplex.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM