|
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;
using System.IO;
using System.NET;
using System.Security.AccessControl;
using System.Security.Principal;
public partial class ACLChange : System.Web.UI.Page
{
//文件夾路徑
private string strDir = "images";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
AddDirectorySecurity();
}
}
/// <summary>
/// 給文件夾添加ASPNET用戶
/// </summary>
private void AddDirectorySecurity()
{
DirectoryInfo dirinfo = new DirectoryInfo(Server.MapPath(strDir));
if ((dirinfo.Attributes & FileAttributes.ReadOnly) != 0)
{
dirinfo.Attributes = FileAttributes.Normal;
}
//取得訪問控制列表
DirectorySecurity dirsecurity = dirinfo.GetAccessControl();
string strDomain = Dns.GetHostName();
dirsecurity.AddAccessRule(new FileSystemAccessRule(strDomain + "http://ASPNET", FileSystemRights.FullControl, AccessControlType.Allow));
dirinfo.SetAccessControl(dirsecurity);
}
}
AspNet技術:Asp.net給站點某目錄增加Aspnet用戶,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。