gpt4 book ai didi

c# - ClaimsPrincipal.Current.FindFirst 尝试创建一个 sql 数据库

转载 作者:太空宇宙 更新时间:2023-11-03 10:28:54 25 4
gpt4 key购买 nike

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)

最佳答案

遇到了同样的问题。将以下内容添加到 web.config 中的 appSettings 为我解决了这个问题

<appSettings>
<add key="enableSimpleMembership" value="false"/>
</appSettings>

关于c# - ClaimsPrincipal.Current.FindFirst 尝试创建一个 sql 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30856584/

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