简体   繁体   English

以编程方式阻止对项目目录的访问

[英]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.

相关问题 如何以编程方式访问此Active Directory作为LocalService? - How to programmatically access this Active Directory as LocalService? Visual Studio:以编程方式在项目目录中创建项目项 - Visual Studio: Programmatically Create Project Items in project directory 以编程方式访问项目文件中的元数据 - Programmatically access metadata from project file 有没有办法用c#以编程方式访问这个PC(windows os)目录? - Is there any way to access This Pc (windows os) directory programmatically with c#? 是否可以使用C#以编程方式访问RDC计算机目录 - Is it possible to access an RDC machine directory programmatically using C# 如何以编程方式访问Active Directory中的“最大密码使用期限”属性? - How to access Maximum Password Age property in Active Directory, programmatically? 我们如何在C#中以编程方式添加对目录的写访问权限? - How we can add write access to a directory programmatically in C#? 以编程方式从C#访问Microsoft Project(MPP)文件 - Programmatically access a Microsoft Project (MPP) file from C# 以编程方式阻止网站 - Block websites programmatically 如何访问 Asp.Net Core 项目之外的图像目录 - How to access images directory outside of the Asp.Net Core Project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM