【问题标题】:ASP MVC Authorize ErrorASP MVC 授权错误
【发布时间】:2014-06-09 18:08:02
【问题描述】:

当我使用时:

[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 - 定位服务器/实例时出错 指定)。

【问题讨论】:

  • 这是使用 AspNet.Indentity 吗?
  • 是 Microsoft.AspNet.Identity.EntityFramework
  • 你有一个 sql server 连接问题。与Authorize无关。
  • 你能展示你的 DbConext 和 web 配置吗?

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


【解决方案1】:

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

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

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

【讨论】:

  • 对我帮助很大,谢谢。你知道为什么需要这个吗?我从 NuGet 下载了 Identity 示例,Web.config 中没有这样的代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-02
  • 1970-01-01
相关资源
最近更新 更多