我正在编写MVC 5并使用Identity 2.0.
现在我想重置密码.但我总是收到重置密码令牌的"无效令牌"错误.
public class AccountController : Controller
{
public UserManager<ApplicationUser> UserManager { get; private set; }
public AccountController()
: this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())))
{
}
Run Code Online (Sandbox Code Playgroud)
我设置了DataProtectorTokenProvider,
public AccountController(UserManager<ApplicationUser> userManager)
{
//usermanager config
userManager.PasswordValidator = new PasswordValidator { RequiredLength = 5 };
userManager.EmailService = new IddaaWebSite.Controllers.MemberShip.MemberShipComponents.EmailService();
var provider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider();
userManager.UserTokenProvider = new Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider<ApplicationUser>(provider.Create("UserToken"))
as IUserTokenProvider<ApplicationUser, string>;
UserManager = userManager;
}
Run Code Online (Sandbox Code Playgroud)
我在发送邮件之前生成密码重置
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> ManagePassword(ManageUserViewModel model)
{
if (Request.Form["email"] != null)
{
var email = …Run Code Online (Sandbox Code Playgroud) 我需要重定向到一个url传递参数作为查询字符串.
这可以包括价值中的&符号.如
string value = "This & That";
Response.Redirect("http://www.example.com/?Value=" + Server.UrlEncode(value));
Run Code Online (Sandbox Code Playgroud)
然而,这会返回http://www.example.com/?Value=This+&+That
我应该用什么来编码这个字符串?
编辑:感谢Luke指出显而易见的,代码确实正常工作.我道歉,毕竟我的问题不是一个有效的问题!
我将要访问的页面有很多旧的遗留代码,它显然正在进行某种编码和解码,使得它看起来好像我的urlencode不能正常工作.
不幸的是,我的解决方案是完全放弃使用&,直到可以重写有问题的代码.难道你不讨厌旧代码!
我只想从url获取完整的查询字符串.
Request.QueryString
Run Code Online (Sandbox Code Playgroud)
Request.ServerVariables["QUERY_STRING"]
我可以使用其中任何一种吗?哪种方式更受欢迎?
谢谢