Asp.net-Mvc
ASP MVC 授權錯誤
當我使用:
[Authorize] public ActionResult Index() { .... return View(); }或者
[Authorize(Users="john")] public ActionResult Index() { .... return View(); }我的腳本執行良好,但當我使用時:
[Authorize(Roles="Admin")] public ActionResult Index() { ..... return View(); }錯誤:
建立與 SQL Server 的連接時發生與網路相關或特定於實例的錯誤。伺服器未找到或無法訪問。驗證實例名稱是否正確以及 SQL Server 是否配置為允許遠端連接。(提供者:SQL 網路介面,錯誤:26 - 錯誤定位伺服器/指定的實例)。
我找到了解決方案。在我的web.config中:
1.<modules> 2.<remove name="FormsAuthenticationModule" /> 3.<remove name="RoleManager" /> 4.</modules>我添加了第 3 行,新的AspNet.Identity程式碼接管了允許我使用
User.IsInRole(..)