WindowsIdentity.Impersonate在ASP.NET中随机出现“用于模拟的无效令牌-不能重复”

时间:2019-05-24 20:02:08

标签: c# asp.net iis windows-identity

我有一个具有HTML 5前端的Web应用程序,该HTML 5前端(通过Ajax和JSON)调用.NET MVC Web应用程序。目的是允许域用户针对Active Directory自动进行身份验证并模拟用户,以便IIS在该用户的上下文中访问网络资源时使用。我当前使用的代码基于以下内容:Impersonate using Forms Authentication。但是,我常常会收到“用于模拟的无效令牌-无法复制”。

网站的层次结构:

Default Web Server
  \-Links_Test     <- This contains the HTML, JavaScript and CSS 
      \-data       <- This is where the C# code runs

我尝试在根级别(Links_Test)和包含MVC代码的节点(Links_Test>数据)上启用ASP.NET模拟,所发生的一切只是浏览器进入了(看似)无限循环提示用户名/密码。我查看过Stack Overflow,并尝试使用Google搜索,但结果不适用或指向过时的资源。

其他相关信息:

  • 使用IIS 10在Windows 10 Pro上开发站点
  • 使用.NET 4.7.2
  • 根据Active Directory对用户进行身份验证

我的目标是将该站点推送到适当的服务器上,并让IIS模拟用户,以便在用户的上下文中执行任何操作。

更新

这是我收到的错误消息:

Invalid token for impersonation - it cannot be duplicated.

at System.Security.Principal.WindowsIdentity.CreateFromToken(IntPtr userToken)
at System.Security.Principal.WindowsIdentity..ctor(SerializationInfo info)
at System.Security.Principal.WindowsIdentity..ctor(SerializationInfo info, StreamingContext context)
at Void .ctor(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)(Object[] )
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateISerializable(JsonReader reader, JsonISerializableContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at TFS.Key2.API.Data_Encryption.EncryptedBuffer.DecryptData[T]() in C:\Source\repos\TFS.Key2.WebSite\TFS.Key2.API.Types\Data Encryption\EncryptedBuffer.cs:line 48
at TFS.Key2.API.Helpers.HttpCookieHelper.GetEncryptedValue[T](HttpCookie Cookie) in C:\Source\repos\TFS.Key2.WebSite\TFS.Key2.API.Types\Helpers\HttpCookieHelper.cs:line 34
at TFS.Key2.WebSite.WebApiApplication.Application_PreRequestHandlerExecute(Object Sender, EventArgs E) in C:\Source\repos\TFS.Key2.WebSite\TFS.Key2.WebSite\Global.asax.cs:line 130
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

0 个答案:

没有答案