关于c#:如何在Medium Trust中写入Web.Config?

关于c#:如何在Medium Trust中写入Web.Config?

How to write to Web.Config in Medium Trust?

将我的第一个大小合适的Web应用程序上载到共享主机,这给我带来了一系列新的挑战,我的意思是不眠之夜。 问题是我最肯定没有开发我的中等信任度应用程序(或有任何线索)。

我缓解了所有问题,保存了一个。

我已经为管理员编写了一个安装程序,以能够指定其连接字符串和其他首选项,但是我找不到以中等信任度写入web.config的方法。 有没有人有解决方案,还是我应该将偏好设置放在另一个文件中?


这实际上听起来像IIS的Low级别。 如果是这样,那么您将无法写入任何文件,而不仅仅是web.config。

以下是IIS帮助文件中的级别:

  • Full (internal) - Specifies unrestricted permissions. Grants the ASP.NET application permissions to access any resource that is subject to operating system security. All privileged operations are supported.

  • High (web_hightrust.config) - Specifies a high level of code access security, which means that the application cannot do any one of the following things by default:

    • Call unmanaged code.
    • Call serviced components.
    • Write to the event log.
    • Access Message Queuing service queues.
    • Access ODBC, OleDb, or Oracle data sources.
  • Medium (web_mediumtrust.config) - Specifies a medium level of code access security, which means that, in addition to High Trust Level restrictions, the ASP.NET application cannot do any of the following things by default:

    • Access files outside the application directory.
    • Access the registry.
    • Make network or Web service calls.
  • Low (web_lowtrust.config) - Specifies a low level of code access security, which means that, in addition to Medium Trust Level restrictions, the application cannot do any of the following things by default:

    • Write to the file system.
    • Call the Assert method.
  • Minimal (web_minimaltrust.config) - Specifies a minimal level of code access security, which means that the application has only execute permissions.

我建议如果您对安装程序一无所知,请让它在内存中创建一个web.config,用户可以在本地保存,然后再保存FTP


推荐阅读