表单身份验证重定向页面显示 401 错误 Mvc4 空项目
form authentication redirect page showing 401 error Mvc4 Empty Project
我试过了
- RedirectToAction
- 重定向
- Url.Action
我正在使用 mvc4 空项目创建申请表身份验证。
这是登录代码
[HttpPost]
[AllowAnonymous]
public ActionResult Index(UserModel user, string returnUrl)
{
try
{
string EmailAddress = user.EmailAddress;
string Password = user.Password;
if (!string.IsNullOrEmpty(EmailAddress) && !string.IsNullOrEmpty(Password) && EmailAddress == "admin@gmail.com" && Password == "admin123")
{
FormsAuthentication.SetAuthCookie(EmailAddress, true);
// Result = new { Status = "Success" };
FormsAuthentication.RedirectFromLoginPage(EmailAddress, true);
return Redirect(Url.Action("Index","Home"));
}
else
{
return RedirectToAction("Index");
}
}
catch (Exception)
{
// logging
throw;
}
}
}
我的过滤器配置
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
filters.Add(new AuthorizeAttribute());
}
}
我是这个部分的新手。我想知道为什么会这样?
重定向到主页后的响应屏幕截图。
我认为授权不起作用,因为您正在尝试使用旧的 FormsAuthentication 方法,而您正在使用使用 OWIN 身份验证的新 AuthorizeAttribute
。
关注这个问题。它应该可以解决您的问题。
我试过了 - RedirectToAction - 重定向 - Url.Action
我正在使用 mvc4 空项目创建申请表身份验证。
这是登录代码
[HttpPost]
[AllowAnonymous]
public ActionResult Index(UserModel user, string returnUrl)
{
try
{
string EmailAddress = user.EmailAddress;
string Password = user.Password;
if (!string.IsNullOrEmpty(EmailAddress) && !string.IsNullOrEmpty(Password) && EmailAddress == "admin@gmail.com" && Password == "admin123")
{
FormsAuthentication.SetAuthCookie(EmailAddress, true);
// Result = new { Status = "Success" };
FormsAuthentication.RedirectFromLoginPage(EmailAddress, true);
return Redirect(Url.Action("Index","Home"));
}
else
{
return RedirectToAction("Index");
}
}
catch (Exception)
{
// logging
throw;
}
}
}
我的过滤器配置
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
filters.Add(new AuthorizeAttribute());
}
}
我是这个部分的新手。我想知道为什么会这样?
重定向到主页后的响应屏幕截图。
我认为授权不起作用,因为您正在尝试使用旧的 FormsAuthentication 方法,而您正在使用使用 OWIN 身份验证的新 AuthorizeAttribute
。
关注这个问题