从Web应用程序中删除.aspx扩展名

时间:2012-05-24 09:25:44

标签: c# asp.net .net vb.net

我是URLRewriting的新手并尝试使用web.config中的以下脚本删除.aspx扩展名

<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>

但是,我没有成功。而且,以下代码块给了我一个错误。

 <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.

我是否需要将重写引擎添加到我的Web应用程序中?

我经历过this link,但我无法理解。

有人可以向我推荐一步一步的流程或样本脚本吗?

4 个答案:

答案 0 :(得分:1)

使用以下规则,每次都像魅力一样!

<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> 

答案 1 :(得分:0)

答案 2 :(得分:0)

好像你没有在类URLupwriter的Web项目中添加dll Reference。添加此引用以解决此问题。

答案 3 :(得分:0)

(作为自己编写的替代方案)

IIS 7 URL重写模块:

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

IIS 5/6:

http://iirf.codeplex.com/