问题如下:通读以了解您需要帮助回答的内容...
我有
- 对比 2013
- 带有 Razor 视图的 MVC 5
- Dapper DAL 自定义 UserManager 和 UserStore/User : IUser< int >
我构建了我自己的 UserManager、RoleManager、UserStore、RoleStore,所有这些都基于 CustomUser:IUser<int> 和 CustomRole:IRole<int>
我可以更改密码、找回忘记的密码、登录、注销……一切都很好。
但是,在剃刀视图中,当我尝试使用时:
User.IsInRole("Administrators");
我从其他一些模块中得到一个 SQL 异常(可能发生在 iPrincipal Identity 类中???):
System.Data.SqlClient.SqlException occurred
_HResult=-2146232060
_message=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)
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
_doNotReconnect=false
Class=20
LineNumber=0
Number=-1
Server=""
State=0
StackTrace:
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
InnerException: <null>
但我可以打电话
var user = AsyncHelpers.RunSync<CloudUser>(() => UserManager.FindByNameAsync(User.Identity.Name));
ViewBag.IsInAdminRole = AsyncHelpers.RunSync<bool>(() => UserManager.IsInRoleAsync(user.Id, "Administrators"));
在我的控制器服务器代码中......
问题:
User.IsInRole 和 UserManager/UserStore 和/或 RoleManager 之间有什么关系
如何在 Razor 视图中获取 User.IsInRole("Administrators") 以“理解”它需要使用我的自定义身份验证实现?