Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • vapenation 21 posts 139 karma points
    Dec 15, 2016 @ 13:23
    vapenation
    0

    How to pass Umbraco user credentials via HttpWebRequest

    I have an application from which I want to make an authenticated call to a backoffice page. More specifically, I want to trigger an Import via Usync. However, to do that, I must pass some user credentials with my call.

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://myumbracosite.local/umbraco/backoffice/usync/uSyncBackOffice/ImportAll");
            req.UseDefaultCredentials = true;
            req.Credentials = new NetworkCredential("[email protected]", "somepassword"); 
    
            HttpWebResponse response = (HttpWebResponse)req.GetResponse();
            response.Close();
    

    In the above example, I pass the username and password of a backoffice via the Network Credentials class. Needless to say, it doesn't work with my Umbracosite returning a 405, method not allowed exception.

    What's the best practice for making an authenticated call to a backoffice page? Do I need to fetch a cookie by first doing a post to the logon page or something of the like?

    If anyone could provide some code samples, I'd be very grateful!

    Thanks in advance!

Please Sign in or register to post replies

Write your reply to:

Draft