asp.net - MVC4 Action 仅在本地调试时触发

标签 asp.net asp.net-mvc asp.net-mvc-4 asp.net-mvc-routing

我有一个用于为我的用户重置密码的操作:

public class Password : Controller{
  public ActionResult Reset(string id)
  {
    //...
  }

}

id 实际上是 加密邮件 当被问及密码恢复用于哪个电子邮件地址时,用户提供的地址。

那么,如果我点击“忘记密码?”链接,并提供电子邮件地址 user@domain.com 发送到用户电子邮件的结果 url 将类似于:

http://www.myapp.com/admin/password/reset/euPdxABQEgE0JDuv6OHSLnk1QBYf73YseBUZwR9+MJA=



这将被路由到上面包含的密码 Controller 上的重置操作。
当我在本地调试应用程序时,这工作正常。
这是不是 在我的测试服务器上工作;我得到的是 404。

趣闻:
  • 如果我从 url 中删除 Id
    http://www.myapp.com/admin/password/reset/我被重定向到
    带有正确消息的密码 Controller 的索引操作
    正如预期的那样“无效链接”。
  • 如果在 id 中包含任何其他字符串(即: http://www.myapp.com/admin/password/reset/abc123 ),我会按预期重定向;如 1) 中所述。

  • 所以这似乎与我传递的 id 的解剖结构有某种关系。我尝试对它进行 url 编码,但这没有用。

    这是管理区域的路由定义:
    public override void RegisterArea(AreaRegistrationContext context)
    {
       context.MapRoute(
          "Admin_default",
          "Admin/{controller}/{action}/{id}",
           new { controller = "Login", action = "Index", id = UrlParameter.Optional }
       );
    }
    

    主要路由是默认路由。

    有任何想法吗?

    最佳答案

    我怀疑这是因为 +登录您的网址的路径部分。你可以看看 following blog post 其中 Scott Hanselman 解释了尝试在路径部分传递此类特殊字符时会遇到的困难。

    我只引用他的结论:

    After ALL this effort to get crazy stuff in the Request Path, it's worth mentioning that simply keeping the values as a part of the Query String (remember WAY back at the beginning of this post?) is easier, cleaner, more flexible, and more secure.



    所以只需删除它并使用以下网址:
    http://www.myapp.com/admin/password/reset?id=euPdxABQEgE0JDuv6OHSLnk1QBYf73YseBUZwR9%2BMJA%3D
    

    请注意我如何对字符串进行 url 编码,这是在 url 中将参数作为查询字符串值传递时应该执行的操作。

    关于asp.net - MVC4 Action 仅在本地调试时触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21683213/

    相关文章:

    javascript - 如何在单击按钮时从代码后面调用 javascript 函数并存储其输出并进一步继续

    asp.net-mvc - 发布到服务器时 MVC ActionLinks 呈现为空

    asp.net-mvc - 当传递给辅助方法时如何获取 <#= Id #> 的值

    string - 如何在 MVC4 中显示字符串 "All"而不是数字?

    c# - AntiForgery token 中的有效字符 __RequestVerificationToken

    asp.net - 如何在Gridview的boundfield中实现文本换行?

    c# - 异步消息发送Asp.net

    javascript - 设置textarea显示:none loses the value when trying to save

    c# - 忽略 ASP.NET Identity 中静态文件的身份验证

    asp.net-mvc - MVC 4 Chrome 要求用户登录两次