ASP MVC 授权错误 [英] ASP MVC Authorize Error

查看:14
本文介绍了ASP MVC 授权错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用时:

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

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

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

My Script Working Well But When I Use :

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

错误:

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

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).

推荐答案

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

I found a solution. In my web.config:

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

<小时>

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


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

这篇关于ASP MVC 授权错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆