How can I run an exe or windows service in medium trust?

寵の児 提交于 2019-12-02 14:26:13

问题


I would like to run exes and Windows Services in Medium Trust, but all the literature I can find suggests using

<system.web>
   <trust level="Medium"/>
</system.web>

for ASP.NET, so I have tried that but using code from How do you check if you are running in Medium Trust environment in .NET? it still appears to have full trust. What is the correct way to do this?


回答1:


The available approaches depend on the .NET version. Prior to .NET 4.0, the CLR enforced CAS policy, which made it possible to restrict permissions for any assembly. However, as of .NET 4.0, the CLR no longer applied CAS policy unless you enable it via the NetFx40_LegacySecurityPolicy element in any given application's app.config file. While this approach is currently available, you might want to keep in mind that it might not be supported in future .NET Framework versions.

The new style of permission limitation is via restriction of permissions by a host other than the "naked" CLR. This is what ASP.NET does, and it's what your alternate hosting platform would need to do as well in order to implement this properly. The simplest mechanism for such permission limitations is via a sandboxed appdomain. I am unfamiliar with Topshelf, and their intro docs don't make it clear whether they support this. However, it would presumably be a relatively simple enhancement, so it might be worth requesting the feature.



来源:https://stackoverflow.com/questions/8229231/how-can-i-run-an-exe-or-windows-service-in-medium-trust

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!