InPlaceHostingManager 托管在 IIS 中,访问被拒绝错误

InPlaceHostingManager Hosted in IIS, Access is denied error

我正在使用 InPlaceHostingManager class 来集成清单文件,以便在 IIS 中托管应用程序后点击一下,我正在尝试获取版本号。请参阅下面的代码

            try
        {
            iphm = new InPlaceHostingManager(new Uri(deployManifestUriStr), false);                
            iphm.GetManifestCompleted += new EventHandler<GetManifestCompletedEventArgs>(iphm_GetManifestCompleted);
            iphm.GetManifestAsync();
        }
        catch (UriFormatException uriEx)
        {
            this._logger.Fatal(uriEx, $"Unable to load Applicaition Versions (Invalid Uri) for uri : {deployManifestUriStr}");
        }
        catch (PlatformNotSupportedException platformEx)
        {
            this._logger.Fatal(platformEx, $"Unable to load Applicaition Versions (Platform Not Supported Exception) for uri : {deployManifestUriStr}");
        }
        catch (ArgumentException argumentEx)
        {
            this._logger.Fatal(argumentEx, $"Unable to load Applicaition Versions (Argument Exception) for uri : {deployManifestUriStr}");
        }
        catch (UnauthorizedAccessException ex)
        {
            this._logger.Fatal(ex);
            this._logger.Fatal(ex.InnerException);
            this._logger.Fatal(ex, $"Unable to load Applicaition Versions (Unauthorized Access Exception) for uri: {deployManifestUriStr}");
        }
        catch (Exception ex)
        {
            this._logger.Fatal(ex, $"Unable to load Applicaition Versions (Exception) for uri : {deployManifestUriStr}");
        }

我收到以下错误

System.UnauthorizedAccessException: Access to the path 'Deployment' 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.Deployment.Application.SubscriptionStore..ctor(String deployPath, String tempPath, ComponentStoreType storeType) at System.Deployment.Application.SubscriptionStore.get_CurrentUser() at System.Deployment.Application.DeploymentManager..ctor(Uri deploymentSource, Boolean isUpdate, Boolean isConfirmed, DownloadOptions downloadOptions, AsyncOperation optionalAsyncOp) at System.Deployment.Application.InPlaceHostingManager..ctor(Uri deploymentManifest, Boolean launchInHostProcess) at Logging.ApplicaitionVersionManifestHelper.Read(String deployManifestUriStr) in

应用程序池 运行 作为网络服务。有谁知道 Deployment 文件夹在哪里?

我查看了 InPlaceHostingManager > DeploymentManager > SubscriptionStore > Get_CurrentUser (CurrentUSer) 我发现了以下内容

        public static SubscriptionStore CurrentUser
    {
        get
        {
            if (_userStore == null)
            {
                lock (_currentUserLock)
                {
                    if (_userStore == null)
                    {
                        string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                        string deployPath = Path.Combine(folderPath, "Deployment");
                        string tempPath = Path.Combine(Path.GetTempPath(), "Deployment");
                        _userStore = new SubscriptionStore(deployPath, tempPath, ComponentStoreType.UserStore);
                    }
                }
            }

            return _userStore;
        }
    }

将代码复制到可以调试的位置后,我发现了以下内容。

string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

上面那行returns什么都没有。这导致我以下 Whosebug Post

此更改为我修复了它

打开 %WINDIR%\System32\inetsrv\config\applicationHost.config 并查找 <applicationPoolDefaults>。在 <processModel> 下,确保您具有以下属性 loadUserProfile="true" setProfileEnvironment="true"

您可以使用 Process Monitor 查看哪个是 Deployment 文件夹。 Process Monitor的使用方法可以参考这个link: Process Monitor