我尝试在Simple FormsAuthentication
MVC5 应用中实施ASP.NET
:
控制器
public ViewResult login()
{
return View();
}
[HttpPost]
public ViewResult login(Login login)
{
if (ModelState.IsValid)
{
if (FormsAuthentication.Authenticate(login.username, login.password))
{
FormsAuthentication.RedirectFromLoginPage(login.username, false);
}
else
{
Response.Write("Invalid username or password. Try again");
return View();
}
}
return View("Index");
}
的Web.Config
<appSettings>
<add key="owin:AutomaticAppStartup" value="false"/>
</appSettings>
<system.web>
<authentication mode="Forms">
<forms
name="PC"
loginUrl="~/Home/login"
timeout="2">
<credentials>
<user name="admin" password="admin1"/>
</credentials>
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
现在,当我提供Web.Config
文件中提到的正确凭据时,来自Else
PostHttp login ViewResult
语句部分的错误消息执行并写入消息
Invalid username or password. Try again
并再次重定向到登录页面。浏览器中显示的URL为:
http://payroll.net:81/Home/login?ReturnUrl=%2f
知道为什么FormsAuthentication没有重定向到&#34;索引&#34;收到正确的凭据后查看?
答案 0 :(得分:2)
您使用未散列的密码提供它,默认散列算法是Sha1尝试散列密码并放入散列字符串。 此外,如果您不想使用加密,可以使用以下命令说明:
<credentials passwordFormat = "Clear">
<user name="UserName"
password="SimplePass"/>
</credentials>