gpt4 book ai didi

asp.net-mvc - ASP MVC 授权错误

转载 作者:行者123 更新时间:2023-12-04 10:51:16 25 4
gpt4 key购买 nike

当我使用:

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

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

我的脚本运行良好,但当我使用时:
[Authorize(Roles="Admin")]
public ActionResult Index() {
.....
return View();
}

错误:

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 中:

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

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

关于asp.net-mvc - ASP MVC 授权错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23269191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com