使用 IdentityServer,当 运行 对 .json 文件的 CreateUser 访问被拒绝时

Using IdentityServer, when running CreateUser access is denied for .json file

我刚刚为新的 .NET Framework 4.7.2 应用程序设置了 IdentityServer。

当我使用标准表单注册用户时,它设法在数据库中创建用户,但是出现以下错误。

Server Error in '/' Application.
Access to the path 'C:\Program Files (x86)\IIS Express190124154304_636839413844068496.json' is denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.UnauthorizedAccessException: Access to the path 'C:\Program Files (x86)\IIS Express190124154304_636839413844068496.json' is denied. 

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user. 

To grant ASP.NET access to a file, right-click the file in File Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

Source Error: 


Line 154:            {
Line 155:                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
Line 156:                var result = await UserManager.CreateAsync(user, model.Password);
Line 157:                if (result.Succeeded)
Line 158:                {

Source File: C:\Repositories\Viper\Viper.Web\Controllers\AccountController.cs    Line: 156 

Stack Trace: 


[UnauthorizedAccessException: Access to the path 'C:\Program Files (x86)\IIS Express190124154304_636839413844068496.json' is denied.]
   System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +12856161
   System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) +776
   System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) +60
   

无法 post 所有 Stacktrace,但如果需要可以上传图像。我完全不明白它为什么要创建这个文件。

如有任何建议,我们将不胜感激。 谢谢

我认为这是 AppPool 执行问题,因此如错误所示,AppPool 的当前身份未被授权访问此 json 文件。

请尝试通过转到 AppPool > 选择高级设置 > 身份 > 选择具有管理员权限的用户并输入他的密码来更改 WebApp 的 AppPool 身份。

然后从 windows cmd(运行 作为管理员):

iisreset

然后重试。