[英]Block access to project directory programmatically
I have a WCF service running in Visual Studio. 我有在Visual Studio中运行的WCF服务。 When running the service, the project's file structure shows up in the browser, and I have a directory containing some files for a user interface. 运行该服务时,项目的文件结构会显示在浏览器中,并且我有一个目录,其中包含一些用于用户界面的文件。
In my Web.config, I have an option (interfaceEnabled) for enabling/disabling the interface. 在我的Web.config中,我有一个用于启用/禁用接口的选项(interfaceEnabled)。 When it is set to disabled, I would like to completely disable access to the directory containing the interface files, but I don't know how to do this. 设置为禁用时,我想完全禁用对包含接口文件的目录的访问,但是我不知道该怎么做。
I know that setting "hiddensegment" in Web.config can do this, but I need to do it programmatically based on the value of interfaceEnabled. 我知道在Web.config中设置“ hiddensegment”可以做到这一点,但是我需要根据interfaceEnabled的值以编程方式进行设置。
How can I do this? 我怎样才能做到这一点? Thanks in advance! 提前致谢!
Without coding the whole thing for you I would use 如果没有为您编写整个代码,我会使用
string setting = WebConfigurationManager.AppSettings["Settingname"]
Then if Setting is true or what ever condition you like, Change the directory permissions using Directory.SetAccessControl 然后,如果“设置”为true或您喜欢的任何条件,请使用Directory.SetAccessControl更改目录权限。
There are a few articles on changing folder permissions in C# I am unsure if this is a good idea to begin with as changing the perms for the folder while your app is running from it might cause issues or not work. 关于C#中更改文件夹权限的几篇文章,我不确定这是否是一个好主意,因为在您的应用程序运行时更改文件夹的权限可能会导致问题或无法正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.