在我之前的应用程序中,一个编码器向全局asax添加了一个函数
虽然我尝试使用PostAuthResponse时没有调用它,但它会调用它
并且Request.IsAuthenticated
返回false,因此我的代码会出错
这是错误
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at ePayment.cc5payment.processorder()
这是全球的asax代码。如何将虚拟用户放入Context.User
protected void Application_PostAuthenticateRequest()
{
if (Request.IsAuthenticated)
{
Context.User = System.Threading.Thread.CurrentPrincipal =
new AuthorizationPrincipal(Context.User.Identity);
}
}
答案 0 :(得分:1)
您应该执行以下操作:
protected void Application_PostAuthenticateRequest()
{
if (Request.IsAuthenticated)
{
GenericIdentity identity = new
GenericIdentity("some_user_name","my_authentication");
Context.User = new GenericPrincipal(genericIdentity, new string[]{});
//this is a list of roles.
}
}
您应该阅读msdn。上的GenericPrincipal课程。