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

2008-02-22 09:35:39来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

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 "\\ASPNET", FileSystemRights.FullControl, AccessControlType.Allow));

dirinfo.SetAccessControl(dirsecurity);
}
}

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:ASP.NET 2.0: 页面中链入的CSS、js文件带中文时需注意

下一篇:asp.net 2.0中预设的cookie