訪問僅限於滿足授權要求的用戶(登錄之後才能訪問主界面及其他界面)
在控制器中想要進行身份驗證的地方加[Authorize]
Web.Config中
添加
<system.web>
<authentication mode="Forms"><forms loginUrl="~/Admin/Login/Index" name="LoginForm"/>
</authentication>
<system.weg>
刪掉或註釋掉
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
</modules>
</system.webServer>
控制器中
登錄的控制器中在用戶名和密碼驗證成功之後,應添加代碼FormsAuthentication.SetAuthCookie(guanliyuan.Name, false);可用User.Identity.Name來獲取當前的登錄名。