WEB.CONFIG:
<authentication mode="Windows"></authentication>
*.CS
...
System.Security.Principal.WindowsImpersonationContext impersonationContext;
impersonationContext = ((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();
....
impersonationContext.Undo();错误信息:"匿名标识不能执行模拟。 "
我设置了,<authentication mode="Windows"></authentication>还要怎么做呢?
<authentication mode="Windows"></authentication>
*.CS
...
System.Security.Principal.WindowsImpersonationContext impersonationContext;
impersonationContext = ((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();
....
impersonationContext.Undo();错误信息:"匿名标识不能执行模拟。 "
我设置了,<authentication mode="Windows"></authentication>还要怎么做呢?
另外在WEB.CONFIG里面直接配置模拟,不在代码中写如何.这样可以指定要模拟的用户
System.Security.Principal.WindowsImpersonationContext impersonationContext;
impersonationContext = ((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();
FileStream fs0 = new FileStream(Server.MapPath(".") + "\\HOME\\register.txt", FileMode.Open, FileAccess.Read);
//打开文本文件
StreamReader sr0 = new StreamReader(fs0, Encoding.Default);
string reg_info = sr0.ReadLine();
sr0.Close();
fs0.Close();
if (reg_info != MACCPU_PASS)
{ int counter;
FileStream fs = new FileStream(Server.MapPath(".") +"\\HOME\\counter.txt", FileMode.Open, FileAccess.Read);
//打开文本文件
StreamReader sr = new StreamReader(fs, Encoding.Default);
string num = sr.ReadLine();
if (num == "")
counter = 0;
else
counter = Int32.Parse(num);
sr.Close();
fs.Close();
if (counter <= 50)
{
int counter_new = counter + 1;
fs = new FileStream(Server.MapPath(".") +"\\HOME\\counter.txt", FileMode.Create, FileAccess.Write);
//建立StreamWriter为写做准备
StreamWriter rw = new StreamWriter(fs, Encoding.Default);
//使用WriteLine写入内容
rw.WriteLine(counter_new.ToString());
//将缓冲区的内容写入文件
//关闭rw对象
rw.Close();
fs.Close();
}
else
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["schoolmanage2005ConnectionString"].ConnectionString);
SqlCommand comm = new SqlCommand("delete from Role_user", conn);
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
Response.Redirect("~/HOME/xueke.aspx");
}
}
impersonationContext.Undo();
关于web.config:
<identity impersonate="true" username="" password=""/>
配置节我凭记忆写的,最好查询msdn确认