如何在Medium Trust中写入Web.Config?

时间:2020-03-05 18:37:22  来源:igfitidea点击:

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

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

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

解决方案:

这实际上听起来像IIS的"低"级别。如果是这样,那么我们将无法写入任何文件,而不仅仅是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"。