ASP.NET MVC网址路线支撑(点) [英] ASP.NET MVC Url Route supporting (dot)

查看:122
本文介绍了ASP.NET MVC网址路线支撑(点)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望你能帮助我下面的问题。

我在IIS7使用ASP.NET MVC 3,并希望我的应用程序以支持用户名与圆点。

例如: HTTP://localhost/john.lee

这是我的Global.asax的样子:(HTTP://本地主机/ {用户名})

  routes.MapRoute(
    UserList的
    {用户名},
    新{控制器=家,行动=ListAll}
);

该应用程序,当我访问其他网页,如 HTTP作品://localhost/john.lee/details

不过,最主要的用户页面无法正常工作,我想应用程序,如Facebook,其中 HTTP工作://www.facebook .COM / john.lee 的支持。

我用低于code,它并没有为我工作的时候:

 <的httpRuntime relaxedUrlToFileSystemMapping =真/>

我可以使用下面code和下载应用程式接受点,但我绝对不会像低于code使用了很多不同的原因,请告诉我有一种方法来解决这个问题

 <模块runAllManagedModulesForAllRequests =FALSE/>


解决方案

一UrlRoutingHandler添加到Web.config。这需要您的网址是多一点但是具体的指标(如/Users/john.lee)。
这迫使每个URL开始/用户将被视为一个MVC网址:

 < system.webServer>
  <&处理GT;
    <添加名称=UrlRoutingHandler
         类型=System.Web.Routing.UrlRoutingHandler,
               System.Web程序,版本= 4.0.0.0,
               文化=中立,
               公钥= b03f5f7f11d50a3a
         PATH =/用户/ *
         动词=GET/>
  < /处理器>
< /system.webServer>

I hope that you can help me with the below problem.

I am using ASP.NET MVC 3 on IIS7 and would like my application to support username's with dots.

Example: http://localhost/john.lee

This is how my Global.asax looks like: (http://localhost/{username})

routes.MapRoute(
    "UserList",
    "{username}",
    new { controller = "Home", action = "ListAll" }
);

The applications works when I access other pages such as http://localhost/john.lee/details etc.

But the main user page doesn't work, I would like the app to work like Facebook where http://www.facebook.com/john.lee is supported.

I used below code and it didn't work for me at all:

<httpRuntime relaxedUrlToFileSystemMapping="true" />

I was able to use below code and get the app to accept dots but I definitely wouldn't like to use below code for many different reason, please tell me there is a way to overcome this problem.

<modules runAllManagedModulesForAllRequests="false" />

解决方案

Add a UrlRoutingHandler to the web.config. This requires your url to be a bit more specific however (f.e. /Users/john.lee). This forces every url starting with /Users to be treated as a MVC url:

<system.webServer>    
  <handlers>      
    <add name="UrlRoutingHandler" 
         type="System.Web.Routing.UrlRoutingHandler, 
               System.Web, Version=4.0.0.0, 
               Culture=neutral, 
               PublicKeyToken=b03f5f7f11d50a3a" 
         path="/Users/*" 
         verb="GET"/>      
  </handlers>
</system.webServer>

这篇关于ASP.NET MVC网址路线支撑(点)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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