Asp.net mvc ASP MVC授权错误

Asp.net mvc ASP MVC授权错误,asp.net-mvc,asp.net-mvc-4,asp.net-mvc-5,asp.net-identity,Asp.net Mvc,Asp.net Mvc 4,Asp.net Mvc 5,Asp.net Identity,当我使用: [Authorize] public ActionResult Index() { .... return View(); } [Authorize(Roles="Admin")] public ActionResult Index() { ..... return View(); } 或 我的脚本运行良好,但当我使用: [Authorize] public ActionResult Index() { .... return Vi

当我使用:

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

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

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

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


我找到了解决办法。在my web.config中:

1。
2.
3.
4.


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

这是使用AspNet.Indentity吗?是的Microsoft.AspNet.Identity.EntityFramework您有sql server连接问题。与
授权无关
。您能展示一下您的DbConext和web配置吗?可能的副本对我帮助很大,谢谢。你知道为什么需要这样做吗?我从NuGet下载了Identity示例,但Web.config中没有此类代码。