ASP.NET MVC忽略"&的.html QUOT;在所有URL的末尾 [英] ASP.NET MVC to ignore ".html" at the end of all url

查看:107
本文介绍了ASP.NET MVC忽略"&的.html QUOT;在所有URL的末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来asp.net MVC和现在URL路由挣扎。我使用asp.net MVC 3 RC2。

I am new to asp.net mvc and now struggling with url routing. I'm using asp.net mvc 3 RC2.

如何创建一个URL路由的忽略尽头的URL扩展。扩展名可以是:的.html 的.aspx 的.php .anything

How can I create a url routing that IGNORES the very end extension in url. the extension can be: .html, .aspx, .php, .anything.

例如,以下网址:

/Home.html
/Home.en
/Home.fr
/Home

应该去首页控制器?

一个例子:

/Home/About.html
/Home/About.en
/Home/About.fr
/Home/About

应该去首页控制器和关于操作。

感谢您:)

推荐答案

我不知道,如果你正在使用IIS7,但如果是这样,那么我会建议其先检查<$ C $结束的URL重写规则C>名为.xyz ,然后做一个重写他们没有名为.xyz

I'm not sure if you're using IIS7, but if so, then I would recommend a rewrite rule which checks for urls ending in .xyz and then doing a rewrites for them without the .xyz.

事情是这样的:

<rewrite>
  <rules>
    <rule name="HtmlRewrite">
      <match url="(.*)(\.\w+)$" />
      <action type="Rewrite" url="{R:1}" />
    </rule>
  </rules>
</rewrite>

这将处理您提出的用例。凡是具有扩展和一些字符结尾将被改写到URL不带扩展名。这样做的好处是,因为一切都进入您的应用程序,而一个你只需要一个途径。

This will handle the use cases you suggested. Anything that ends with an extension and some characters will be rewritten to a url without the extension. The benefit of this is that you will only need one route because everything goes into your application without one.

这篇关于ASP.NET MVC忽略&QUOT;&的.html QUOT;在所有URL的末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆