如何更改 ASP.NET 中的信任级别

How to change trust levels in ASP.NET

当我将网络应用程序部署到外部托管服务提供商时,我不断收到以下错误消息:

Security Exception

Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

经过一些研究,我认为这是因为我使用的提供商不允许 Web 应用程序具有完全信任级别,因为这些应用程序位于共享服务器上。 (I'm using Fasthosts).

但是,当我通过以下方式将信任级别更改为部分/最小时:

<securityPolicy>
  <trustLevel name="Minimal" policyFile="web_minimaltrust.config"/>
</securityPolicy>

我现在得到:

Parser Error Message: This configuration section cannot be used at this path. This happens when the site administrator has locked access to this section using <location allowOverride="false"> from an inherited configuration file.

这意味着提供商阻止我更改应用程序的信任级别。

所以我的问题是:如果 ASP.NET 默认对应用程序完全信任,但共享服务器只允许部分信任并且不允许您通过 web.config 文件覆盖它,我该如何更改我的应用程序的信任级别?

(我一直在兜圈子,所以我可能完全搞错了!)

错误表明 IIS 配置为 运行 较低的信任级别(很可能是中等信任级别)并且不允许 Web 应用程序覆盖主配置文件。如果您的虚拟主机不允许您覆盖主要配置,您将无法使用完全信任级别。

在这种情况下,您可以询问您的虚拟主机提供商是否允许您使用完全信任级别。如果他们拒绝,您将不得不将您的 Web 应用程序配置为具有中等信任级别的 运行 或移动到支持 Full Trust level hosting.

的 Web 主机