Asp.net mvc 5 查询字符串参数不是asp.net mvc操作中的url编码
我正在通过电子邮件调用ResetPassword操作(ASP.NET MVC 5) 这是我浏览器中的地址 但是,在调试中,我在ResetPassword操作中收到此字符串:Asp.net mvc 5 查询字符串参数不是asp.net mvc操作中的url编码,asp.net-mvc-5,urlencode,Asp.net Mvc 5,Urlencode,我正在通过电子邮件调用ResetPassword操作(ASP.NET MVC 5) 这是我浏览器中的地址 但是,在调试中,我在ResetPassword操作中收到此字符串: // GET: /Account/ResetPassword [AllowAnonymous] public ActionResult ResetPassword(string code) { return code == null ? View("Error") : View
// GET: /Account/ResetPassword
[AllowAnonymous]
public ActionResult ResetPassword(string code)
{
return code == null ? View("Error") : View();
}
“代码”是:
BwEA181bAECFMcn1vwPdrctS/wcyncKPxGT9Zx1tDuPwKGpe9H1W7LI3Zm9fM 3aA5Fok5GhLPBHqbtiGfpL8Cmdx7RNC6RJ7d6t9ZgFBwgwYk3zssU1Nh64PWHJAabVG9Wv9VWDNdj Fz0UA712XA==
i、 例如,它不是url编码的,当然也不会使用无效的令牌消息重置密码
如何在操作中获得正确的字符串 可以用以下方式对字符串进行编码:
[AllowAnonymous]
public ActionResult ResetPassword(string code)
{
code = Server.HtmlEncode(code);
}
有关如何编码的更多信息,请参见我仍然不知道是什么问题。看起来它一开始就不应该起作用。我希望我知道为什么微软觉得需要使用带有斜杠和加号的代币 无论如何,我只是对令牌进行Base64编码和解码,如下所示: 在向用户发送电子邮件之前:
[AllowAnonymous]
public ActionResult ResetPassword(string code)
{
code = Server.HtmlEncode(code);
}
string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
code = CommonFuncs.Base64Encode(code);
EmailsBL.PasswordResetEmail(model.Email, code); <-- emailing the link for password rest to the user
// POST: /Account/ResetPassword
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> ResetPassword(ResetPasswordViewModel model)
{
/////////////////////////////////////////////////////////////////////
// NOTE: if email is not CONFIRMED then reset password silently fails
////////////////////////////////////////////////////////////////////
if (!ModelState.IsValid)
{
return View(model);
}
model.Code = CommonFuncs.Base64Decode(model.Code);
public static string Base64Encode(string plainText)
{
string base64string = null;
if (plainText != null)
{
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
base64string = System.Convert.ToBase64String(plainTextBytes);
}
return base64string;
}
public static string Base64Decode(string base64EncodedData)
{
string decodedBase64String = null;
if (base64EncodedData != null)
{
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
decodedBase64String = System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
}
return decodedBase64String;
}