使用加号字符的ASP MVC(属性)路由

时间:2015-04-13 17:46:44

标签: c# asp.net-mvc

我有以下路线:

[Route("konto/validera-epost/{email}/{hash}")]
public ActionResult ValidateEmail(string email, string hash)

这很有用,有人使用带有" +"的电子邮件。在其中,如:

http://localhost:53529/konto/validera-epost/niels%2btest1%40bosmainteractive.se/4eac5247b9e6c9ae2a020957a54dd644

结果只是得到一个空白页面。

1 个答案:

答案 0 :(得分:1)

这很可能是由于IIS中的安全设置阻止了网址中的+

要解决(或覆盖/禁用),请在IIS中更改它,或者在web.config中更改,如下所示:

<system.webServer>
  <security>
    <requestFiltering allowDoubleEscaping="true" />
  </security>
</system.webServer>

参考文献:
  - http://www.ifinity.com.au/Blog/EntryId/60/404-Error-in-IIS-7-when-using-a-Url-with-a-plus-sign-in-the-path
  - https://serverfault.com/questions/76013/iis6-vs-iis7-and-iis7-5-handling-urls-with-plus-sign-in-base-not-querystr

注意:我已经看到了启用此选项的一些安全问题。在使用实时环境之前,我建议您更多地阅读此功能。

根据@ Ryan的评论进行编辑:

  

[..]您可以在动作级别使用属性[ValidateInput(false)]

来应用此功能