Displaying External Content In MVC RRS feed

  • Question

  • User1929067570 posted

    In this example i have 401 not authorized error in GetResponse() method.

    The URL has an authentication required popup, and i want to access to the webpage directly.

    public ActionResult Contact()
                var request = (HttpWebRequest)WebRequest.Create("URL") ;
                request.Method = "GET";
                var cred = new NetworkCredential("User", "Password","Domain");
                var cache = new CredentialCache();
                cache.Add(new Uri("URL"), "Basic", cred);
                request.Credentials = cache;
                var response = (HttpWebResponse)request.GetResponse();
                return Redirect(response.ResponseUri.ToString());


    Monday, March 4, 2019 11:37 AM

All replies

  • User-474980206 posted
    You should check the response header www-authenticate to see if basic is supported. If so then the user name or password is wrong.
    Monday, March 4, 2019 3:19 PM
  • User-2054057000 posted

    The API method needs you to provide your Username and Password for accessing it.

    You have to find out how to send the credentials to the API i.e. either in through JSON, or through form or through http header.

    Once you find out this then you can send the credentials to the API when making the API call.

    Consuming ASP.NET Web API is the perfect article which you should reference here.

    Tuesday, March 5, 2019 5:26 AM