Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.NET-关于模拟的难题_Asp.net - Fatal编程技术网

ASP.NET-关于模拟的难题

ASP.NET-关于模拟的难题,asp.net,Asp.net,我正在构建一个ASP.NET应用程序。应用程序使用表单身份验证。我没有使用角色。但是,我的帐户有一个与之关联的标志,表示我是管理员 作为管理员,我想通过Server.Execute调用应用程序中的另一个页面。当我调用此页面时,我希望将其作为应用程序中的另一个用户调用 这可能吗?如果是,我该怎么做?我知道如何运行Server.Execute。把它称为不同的用户给我带来了困难。我想这可以通过模仿来完成。但我不知道怎么做 谢谢大家! 在调用页面之前,只需将当前主体(admin)替换为要模拟的主体(我们

我正在构建一个ASP.NET应用程序。应用程序使用表单身份验证。我没有使用角色。但是,我的帐户有一个与之关联的标志,表示我是管理员

作为管理员,我想通过Server.Execute调用应用程序中的另一个页面。当我调用此页面时,我希望将其作为应用程序中的另一个用户调用

这可能吗?如果是,我该怎么做?我知道如何运行Server.Execute。把它称为不同的用户给我带来了困难。我想这可以通过模仿来完成。但我不知道怎么做


谢谢大家!

在调用页面之前,只需将当前主体(admin)替换为要模拟的主体(我们讨论的是ASP.Net模拟,而不是Windows)

var identity = new GenericIdentity("username");
//Roles get populated for username    
var principal = new RolePrincipal(identity); 
//Current thread now impersonated as "username"
Thread.CurrentThread.CurrentPrincipal = principal;
Server.Execute("whatever.aspx");