Click here to Skip to main content
15,891,597 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
So the problem is when I use a WebClient to called a generic handler which need to access User.Identity methods.

ASP.Net code (running it on page load for testing)
C#
WebClient client = new WebClient();
string result = client.DownloadString(urlBase + "/scripts/somescript.ashx?id=jdskhfk34");


and the generic handler:
C#
public class playbackCount : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)
    {
        if (context.User.Identity.IsAuthenticated)
            {
             //code
            }
    }
}


User is logged in (and the session hasn't time out) but when I called the handler it always shows that the user is not authenticated. But if I call it directly (from browser) it indicates true (as expected).

Any suggestion on why and how to fix this.
Posted
Updated 5-Jul-12 5:51am
v2
Comments
Zumicts 5-Jul-12 12:20pm    
Bet this is just a bug or something with ASP.Net

1 solution

Before you calling the actual WebClient DownloadString functionality, You may have to set the Credentials Property to the WebClientobject. i.e
C#
WebClient client = new WebClient();
client.Credentials = CredentialCache.DefaultCredentials;// Use ASP.Net default credential

// Do Download or some other staff.
// ...

For more see MSDN[^] article.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900