user1688401
user1688401

Reputation: 1871

set Context.User to something in Application_PostAuthenticateRequest

In my application before me one coder added a function to global asax although it is not called anywhere when I try to PostAuthResponse it calls this and Request.IsAuthenticated is return false so my codes give error this is error

   at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
   at System.Net.HttpWebRequest.GetRequestStream()
   at ePayment.cc5payment.processorder()

This is the global asax code. How do I put a dummy user into Context.User

 protected void Application_PostAuthenticateRequest()
    {
        if (Request.IsAuthenticated)
        {
            Context.User = System.Threading.Thread.CurrentPrincipal =
                new AuthorizationPrincipal(Context.User.Identity);
        }
    }

Upvotes: 2

Views: 3016

Answers (1)

gideon
gideon

Reputation: 19465

You should do the following:

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.
    }
}

You should read about the GenericPrincipal class on msdn.

Upvotes: 2

Related Questions