string _path = String.Format("IIS://{0}/w3svc/{1}", Environment.MachineName, flag);
DirectoryEntry de = new DirectoryEntry(_path);
de.Properties["AnonymousUserName"][0] = UserName;
de.Properties["AnonymousUserPass"][0] = UserPass;
de.CommitChanges();
_path = String.Format("IIS://{0}/w3svc/{1}/root", Environment.MachineName, flag);
de = new DirectoryEntry(_path);
de.Properties["AnonymousUserName"][0] = UserName;
de.Properties["AnonymousUserPass"][0] = UserPass;
de.CommitChanges();
这里一定要注意,这两个地方都要修改,当初就是这个问题,导致总是在访问的时候,出现登陆框的.
当然,也可以直接通过脚本区设置:
adsutil.vbs set /w3svc/502540610/root/AnonymousUserName "username"
adsutil.vbs set /w3svc/502540610/root/AnonymousUserPass "password"
只修改密码就可以了,两个地方都会随着更改的.