当前位置:首页 > Asp.net给站点某目录增加Aspnet用户

Asp.net给站点某目录增加Aspnet用户

点击次数:1404  更新日期:2010-12-25
\n

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


\n

using System.IO;
using System.Net;
using System.Security.AccessControl;
using System.Security.Principal;


\n

public partial class ACLChange : System.Web.UI.Page
{
//文件夹路径
private string strDir = “images”;


\n

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
AddDirectorySecurity();
}
}


\n

/// <summary>
/// 给文件夹添加ASPNET用户
/// </summary>
private void AddDirectorySecurity()
{
DirectoryInfo dirinfo = new DirectoryInfo(Server.MapPath(strDir));


\n

if ((dirinfo.Attributes & FileAttributes.ReadOnly) != 0)
{
dirinfo.Attributes = FileAttributes.Normal;
}


\n

//取得访问控制列表
DirectorySecurity dirsecurity = dirinfo.GetAccessControl();


\n

string strDomain = Dns.GetHostName();


\n

dirsecurity.AddAccessRule(new FileSystemAccessRule(strDomain + “\\\\ASPNET”, FileSystemRights.FullControl, AccessControlType.Allow));


\n

dirinfo.SetAccessControl(dirsecurity);
}
}


\n

来源:网络

\n