gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 23:27:59 26 4
gpt4 key购买 nike

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

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/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com