ASP MVC Authorize Error

笑着哭i 提交于 2019-12-01 01:54:27

问题


When I Use :

[Authorize]
public ActionResult Index() {
    ....
    return View();
}

OR

[Authorize(Users="john")]
public ActionResult Index() {
    ....
    return View();
}

My Script Working Well But When I Use :

[Authorize(Roles="Admin")]
public ActionResult Index() {
    .....
    return View();
}

Error:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified).


回答1:


I found a solution. In my web.config:

1.<modules>
2.<remove name="FormsAuthenticationModule" />
3.<remove name="RoleManager" />
4.</modules>

I added the line 3, and the new AspNet.Identity code took over allowing me to use User.IsInRole(..)



来源:https://stackoverflow.com/questions/23269191/asp-mvc-authorize-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!