0

我正在 ASP.NET 中实现我自己的重置密码。在重置密码中,首先我创建一个随机字符串并将其邮寄到用户电子邮件。对于电子邮件中的链接,例如http://xyz.com/account/forgot?random=xxxx&userid=xx 。我创建了一个 httpget 类型操作忘记显示哪个如果 randomid 和 userid 被验证,则返回带有密码输入标签的视图。但是在httppost类型的忘记中,我对参数感到困惑。我忘记了具有 2 个属性密码和确认密码的模型。如果我只是将 forgotmodel 传递给 httppost 操作,那么我无法从数据库中查询用户。我想我应该将 randomId 作为参数传递。但是,我正在了解如何从 httpget 操作的 url 获取 randomID (如果我这样做,它安全吗?)?请指导我,我被卡住了..提前谢谢

4

1 回答 1

1

您是否使用类似 Html.BeginForm("action","controller"),如果是这样,那么您将丢失查询字符串参数。由于 ForGotPassword(..) 的 HttpGet 和 HttpPost 方法具有相同的操作名称,您可以只使用 Html.BeginForm()。因此,表单会将数据发布到页面 url,并且您将获得查询字符串。

在您的 http post 方法中,您可以定义如下,

    [HttpPost]
    public ActionResult ForGot(ForgotModel model, string random,strung userid)
    {
     :
     :
    }
  • 如果您不想遵循上述方法,则在 httpget 方法中写入 ViewBag/ViewData 并将它们作为隐藏字段放在视图中。然后您可以接收它们作为 Method 的输入。

    [HttpGet]
    public ActionResult ForGot(string random,strung userid)
    {
     ViewBag.Random =random;
     Viewbag.Userid =userid;
     :
     :
    } 
    [HttpPost]
    public ActionResult ForGot(ForgotModel model, string random,strung userid)
    {
     :
     :
    }
    

并且 , 鉴于

@Html.BeginForm("ForGot","Account"){
:
 @Html.Hidden(ViewBag.Random)
 @Html.Hidden(ViewBag.Userid)
:
}
于 2013-04-13T17:39:48.483 回答