Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9053927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:32:58+00:00 2026-06-16T13:32:58+00:00

We are using web service with basic authentication. It all worked all fine, till

  • 0

We are using web service with basic authentication.
It all worked all fine, till owners of web service implemented balancing service.
Which is simply redirects requests to different instances of web service.

The problem is that after being redirected basic authentication fails.
There is “request authentication credentials was not passed” exception.

Additional info:

  1. We have to create request manually.

        var req = (HttpWebRequest)WebRequest.CreateDefault(new Uri(Settings.Default.HpsmServiceAddress));
    
        req.Headers.Add("Authorization", "Basic aaaaaaaaaaa");
        req.PreAuthenticate = true;
        req.AuthenticationLevel = AuthenticationLevel.MutualAuthRequested;
        req.UserAgent = "Apache-HttpClient/4.1.1 (java 1.5)";
        req.KeepAlive = false;
    
        ServicePointManager.Expect100Continue = false;
    
        req.ContentType = "text/xml; charset=utf-8";
        req.Method = "POST";
        req.Accept = "gzip,deflate";
        req.Headers.Add("SOAPAction", actionName);
        byte[] buffer = Encoding.UTF8.GetBytes(envelop);
        Stream stm = req.GetRequestStream();
        stm.Write(buffer, 0, buffer.Length);
        stm.Close();
    
        WebResponse response = req.GetResponse();
        string strResponse = new StreamReader(response.GetResponseStream()).ReadToEnd();
        response.Dispose();
    
  2. We are redirected with HTTP 307 redirect

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T13:32:59+00:00Added an answer on June 16, 2026 at 1:32 pm

    Follow the MSDN for HttpWebRequest.AllowAutoRedirect Property i found this :

    The Authorization header is cleared on auto-redirects and
    HttpWebRequest automatically tries to re-authenticate to the
    redirected location. In practice, this means that an application can’t
    put custom authentication information into the Authorization header if
    it is possible to encounter redirection. Instead, the application must
    implement and register a custom authentication module. The
    System.Net.AuthenticationManager and related class are used to
    implement a custom authentication module. The
    AuthenticationManager.Register method registers a custom
    authentication module.

    Solution is to write a custom Authentication Module.

    Here what i’ve found about it :

    http://msdn.microsoft.com/en-us/library/system.net.authenticationmanager.aspx

    And here the AllowAutoRedirect properties page :

    http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.allowautoredirect.aspx

    UPDATE

    Can you try to use CredentialCache instead of add header to webrequest ?

    CredentialCache myCache = new CredentialCache();
    
    myCache.Add(
    new Uri("http://www.contoso.com/"),"Basic",new NetworkCredential(UserName,SecurelyStoredPassword));
    req.Credentials = myCache;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on adding basic authentication to my RESTful web service (implemented using Spring
We have a very basic SOAP web service setup using Windows Authentication, open for
I trying to invoke a web service, which has an Basic HTTP Authentication. I
I am creating a REST Web Service using Java and Jersey API. The basic
i am using web service asmx, whenever a new request comes, all objects will
I'm using a web service which returns a list of products. I created a
Having some trouble using basic authentication with a simple test Wcf service. I am
I am attempting to add BASIC authentication to a RESTful web service that I
I am attempting to add BASIC authentication to my RESTful web-service. Currently I have
I am trying to host a WCF web service in IIS using Windows Authentication.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.