访问仅限于满足授权要求的用户(登录之后才能访问主界面及其他界面)
在控制器中想要进行身份验证的地方加[Authorize]
Web.Config中
添加
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Admin/Login/Index" name="LoginForm"/>
</authentication>
<system.web>
删掉或注释掉
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
</modules>
</system.webServer>
控制器中
登录的控制器中在用户名和密码验证成功之后,应添加代码FormsAuthentication.SetAuthCookie(guanliyuan.Name, false);可用User.Identity.Name来获取当前的登录名。