在制作安装文件部署web程序时,如何修改某一文件夹的访问权限和IIS网站的属性

chenxiaoguo 2009-05-04 12:27:47
rt,谢谢各位
...全文
265 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
LGP88864237 2009-05-05
  • 打赏
  • 举报
回复
楼上说的很对,要添加安装类
jackljane 2009-05-05
  • 打赏
  • 举报
回复

1.在web应用程序下添加一个安装类。
2.在安装类里调用下面的类 // 下面的类将对文件或文件夹授权


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.AccessControl;
using System.Runtime.Remoting.Contexts;

namespace KilergHorse.WebSetupAction
{
public class SkyDirectoryRule
{
public static void SetAccessRule(string strPath)
{
SkyDirectoryRule skr = new SkyDirectoryRule();
skr.SetTempAccessRule(strPath);
}

private void SetTempAccessRule(string strPath)
{
try
{
//临时图象文件
if (!Directory.Exists(strPath)) return;
string fullTempPath = strPath + "\\Temp";
AddDirectorySecurity(fullTempPath, "Everyone", FileSystemRights.FullControl, AccessControlType.Allow);

//日志文件
string fullLogPath = strPath + "\\Log";
AddDirectorySecurity(fullLogPath, "Everyone", FileSystemRights.FullControl, AccessControlType.Allow);

//修改webconfig.xml
string fullWebName = strPath + "\\web.config";
AddDirectorySecurity(fullWebName, "Everyone", FileSystemRights.Modify, AccessControlType.Allow);

//修改App_Data\admin.xml
string fullAdminName = strPath + "\\App_Data\\admin.xml";
AddDirectorySecurity(fullAdminName, "Everyone", FileSystemRights.Modify, AccessControlType.Allow);
}
catch (Exception oe)
{
throw oe;
}
}

// Adds an ACL entry on the specified directory for the specified account.
private void AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
{
// Create a new DirectoryInfo object.
DirectoryInfo dInfo = new DirectoryInfo(FileName);

// Get a DirectorySecurity object that represents the
// current security settings.
DirectorySecurity dSecurity = dInfo.GetAccessControl();

// Add the FileSystemAccessRule to the security settings.
dSecurity.AddAccessRule(new FileSystemAccessRule(Account,
Rights, InheritanceFlags.ObjectInherit, PropagationFlags.NoPropagateInherit,
ControlType));
// Set the new access settings.
dInfo.SetAccessControl(dSecurity);
}

// Removes an ACL entry on the specified directory for the specified account.
public static void RemoveDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
{
// Create a new DirectoryInfo object.
DirectoryInfo dInfo = new DirectoryInfo(FileName);

// Get a DirectorySecurity object that represents the
// current security settings.
DirectorySecurity dSecurity = dInfo.GetAccessControl();

// Add the FileSystemAccessRule to the security settings.
dSecurity.RemoveAccessRule(new FileSystemAccessRule(Account,
Rights,
ControlType));

// Set the new access settings.
dInfo.SetAccessControl(dSecurity);

}

}
}
wuyq11 2009-05-04
  • 打赏
  • 举报
回复
在安装部署里操作安装类,控制IIS虚拟目录实现控制。
参考
Adechen 2009-05-04
  • 打赏
  • 举报
回复
路过,取经了
itcrazyman 2009-05-04
  • 打赏
  • 举报
回复
顶楼上
蓝海D鱼 2009-05-04
  • 打赏
  • 举报
回复

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧