我的自定义成员提供程序有问题,它扩展了ExtendedMembershipProvider。
在运行成功执行我实现的Validate方法的WebSecurity.Login之后,没有设置User.Identity.IsAuthenticated。
但是检查一下WebSecurity.IsAuthenticated,这是真的。此外,CurrentUserName设置为我的用户名。但是CurrentUserId说“抛出了一个异常”。
如果我检查了异常,并且在检查了代码之后,我发现我的提供者的GetUser(string username,bool isUserOnline)方法将用户名参数接收为null...
发布于 2013-09-10 06:55:24
我刚刚发现了我的问题。在我的控制器登录操作中,我返回了一个视图。据我所知,我必须使用RedirectToAction,因为用户是在执行请求后设置的。
这是我所拥有的:
public ActionResult Index(LoginModel model)
{
if (ModelState.IsValid)
{
WebSecurity.Login(model.Email, model.Password, model.RememberMe)
}
return View(model);
}这是我现在所拥有的,并且是有效的:
public ActionResult Index(LoginModel model)
{
if (ModelState.IsValid && WebSecurity.Login(model.Email, model.Password, model.RememberMe))
{
return RedirectToAction("Index", "Home");
}
return View(model);
}发布于 2018-04-28 13:13:30
我也有同样的问题。在我的例子中,会话没有被创建,因为它被设置为不同的域。请更改它或删除web.config文件中的域,如下所示。
<authentication mode="Forms">
<forms name="test" loginUrl="/login" protection="All" path="/" domain=".xxxx.xx" />
</authentication>https://stackoverflow.com/questions/18708171
复制相似问题