2

在我之前的应用程序中,一位编码员向全局 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);
        }
    }
4

1 回答 1

2

您应该执行以下操作:

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类。

于 2013-05-31T09:08:06.947 回答