ASP MVC授权错误

时间:2014-04-24 12:41:06

标签: asp.net-mvc asp.net-mvc-4 asp.net-mvc-5 asp.net-identity

当我使用时:

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

OR

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

我的脚本运行良好但我使用时:

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

错误:

  

发生与网络相关或特定于实例的错误    建立与SQL Server的连接。找不到服务器或    无法访问。验证实例名称是否正确    SQL Server配置为允许远程连接。 (提供者:SQL    网络接口,错误:26 - 查找服务器/实例时出错    指定)。

1 个答案:

答案 0 :(得分:11)

我找到了解决方案。在我的 web.config

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

我添加了第3行,新的 AspNet.Identity 代码接管后允许我使用User.IsInRole(..)

相关问题