Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.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
Visual Studio ASP.Net模拟身份问题_Asp.net_Authentication_Visual Studio 2013_Impersonation - Fatal编程技术网

Visual Studio ASP.Net模拟身份问题

Visual Studio ASP.Net模拟身份问题,asp.net,authentication,visual-studio-2013,impersonation,Asp.net,Authentication,Visual Studio 2013,Impersonation,我目前正在为我的intranet asp.net站点使用windows身份验证。我希望我的站点的一部分只对我指定的windows用户组(管理员)中的用户可用,并授予访问权限。到目前为止,我的工作还不错,IIS中的ASP.net模拟设置为“Authenticated User”。我还想从网络位置下载一个文件到客户端计算机。我通过以下代码执行此操作: Protected Sub Button1Click(ByVal sender As Object, ByVal e As System.EventA

我目前正在为我的intranet asp.net站点使用windows身份验证。我希望我的站点的一部分只对我指定的windows用户组(管理员)中的用户可用,并授予访问权限。到目前为止,我的工作还不错,IIS中的ASP.net模拟设置为“Authenticated User”。我还想从网络位置下载一个文件到客户端计算机。我通过以下代码执行此操作:

Protected Sub Button1Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim path3 As String = "file path here"
    Dim fi As New FileInfo(path3)
    HttpContext.Current.Response.Clear()
    HttpContext.Current.Response.ContentType = "application\msword"
    HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" & fi.Name)
    HttpContext.Current.Response.WriteFile(fi.FullName)
    HttpContext.Current.Response.Flush()
    HttpContext.Current.Response.Close()
End Sub
这同样有效,但前提是我将ASP.net模拟从经过身份验证的用户切换到特定用户。我已检查,并且特定用户和经过身份验证的用户都可以访问文件路径。例如,我使用windows帐户JonW登录,该帐户是组域用户的一部分。我知道域用户可以访问我要下载的文件

如果我没有使用特定用户,那么当我单击按钮尝试下载文件时,会弹出一个windows安全窗口,询问我的信息。当我输入信息时(因为我已经登录了,所以无论如何我都不想这么做),它会等待15秒,然后再次询问。这会重复5次左右,直到它告诉我我没有访问权限(我知道我有)

因此,显而易见的解决方案是使用特定的模拟帐户,对吗?不,因为当我尝试访问站点的admins部分时,我无法访问,因为它使用的是特定的模拟用户,而不是admin组中经过身份验证的用户。我可以让特定的模拟帐户访问该站点的该部分,但这样每个人都可以进入,这是我不想要的


因此,我的问题是,我如何使用特定的模拟用户下载文件,以及如何使用经过身份验证的用户访问管理部分,或者,我如何始终使用经过身份验证的用户并摆脱windows安全弹出窗口,并使其自动使用经过身份验证的用户凭据

我有点困惑,为什么你认为你首先需要模仿任何人。除非您需要特定于该用户的网络凭据,否则无需模拟任何人,但通常情况下并非如此

例如,在您的情况下,您可以简单地以应用程序池用户的身份运行站点,该用户在后台将通过网络作为域上机器的凭据进行身份验证。因此,如果您的IIS服务器名称为“Webserver”,则只需授予访问文件所需的共享/文件夹/资源的
\\Domain\$Webserver
访问权限,然后您就可以使用标准Windows身份验证来控制对应用程序中这些资源的访问

因此,如果您不希望“普通”用户访问站点的这一部分,只需拒绝他们通过标准ASP.NET身份验证工具(web.config等)进行访问

如果您需要为用户提供对该区域的访问权限,但只允许他们访问某些文件,而不允许他们访问其他文件,那么这将变得更加复杂,但仍然不太困难