ClaimsPrincipal.Current.FindFirst
应该返回null,但是它尝试查找角色,找不到它们然后尝试在我的app_Data文件夹中创建mdf文件...
我应该抓住并吞下异常,还是有办法告诉它不要尝试创建数据库文件?
这是堆栈跟踪:
System.UnauthorizedAccessException: Access to the path 'C:\inetpub\Web\App_Data' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost)
at System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost)
at System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString)
at System.Web.DataAccess.SqlConnectionHelper.EnsureDBFile(String connectionString)
at System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation)
at System.Web.Security.SqlRoleProvider.GetRolesForUser(String username)
at WebMatrix.WebData.SimpleRoleProvider.GetRolesForUser(String username)
at System.Web.Security.RolePrincipal.GetRoles()
at System.Web.Security.RoleClaimProvider.<get_Claims>d__0.MoveNext()
at System.Security.Claims.ClaimsIdentity.<get_Claims>d__0.MoveNext()
at System.Security.Claims.ClaimsIdentity.FindFirst(String type)
at System.Security.Claims.ClaimsPrincipal.FindFirst(String type)
答案 0 :(得分:2)
有同样的问题。在web.config中添加以下appSettings为我解决了它
<appSettings>
<add key="enableSimpleMembership" value="false"/>
</appSettings>