Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. http BASIC authentication question

http BASIC authentication question

Scheduled Pinned Locked Moved ASP.NET
securityquestioncsharpasp-netdatabase
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bkaufman43
    wrote on last edited by
    #1

    I am relatively new to Asp.Net. Here's my question: I need to do a simple http POST to a service URL (at a different domain) with all the parameters in the query string. For security purposes the service URL is using http BASIC authentication under https. I need to add an "Authorization" header with a Base64 encoded username and password to gain access to the service. For the sake of illustration, assuming the login is: Abcdef and the password is aBC123abc -- what would the coding look like (in VB)? Where specifically would the coding be placed? Thanks!

    Bruce K.

    F 1 Reply Last reply
    0
    • B Bkaufman43

      I am relatively new to Asp.Net. Here's my question: I need to do a simple http POST to a service URL (at a different domain) with all the parameters in the query string. For security purposes the service URL is using http BASIC authentication under https. I need to add an "Authorization" header with a Base64 encoded username and password to gain access to the service. For the sake of illustration, assuming the login is: Abcdef and the password is aBC123abc -- what would the coding look like (in VB)? Where specifically would the coding be placed? Thanks!

      Bruce K.

      F Offline
      F Offline
      Felipe Dalorzo
      wrote on last edited by
      #2

      String auth = userID + ":" + password; byte[] binaryData = Encoding.UTF8.GetBytes(auth); auth = Convert.ToBase64String(binaryData); // Using base64 encoding auth = "Basic " + auth; //This specifies it to use Basic Authentication // Prepare web request HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(myURL); // Add the standard headers webRequest.Method = "POST"; webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.ContentLength = 0; // Add this additional header webRequest.Headers[“AUTHORIZATION”] = auth; HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

      B 1 Reply Last reply
      0
      • F Felipe Dalorzo

        String auth = userID + ":" + password; byte[] binaryData = Encoding.UTF8.GetBytes(auth); auth = Convert.ToBase64String(binaryData); // Using base64 encoding auth = "Basic " + auth; //This specifies it to use Basic Authentication // Prepare web request HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(myURL); // Add the standard headers webRequest.Method = "POST"; webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.ContentLength = 0; // Add this additional header webRequest.Headers[“AUTHORIZATION”] = auth; HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

        B Offline
        B Offline
        Bkaufman43
        wrote on last edited by
        #3

        Thank you very much Felipe! Ok - here come the "dumb" questions - sorry! Where do I place this code?: String auth = userID + ":" + password; byte[] binaryData = Encoding.UTF8.GetBytes(auth); auth = Convert.ToBase64String(binaryData); // Using base64 encoding auth = "Basic " + auth; //This specifies it to use Basic Authentication Does this go in the web.config file? If not where? Same question for: // Prepare web request HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(myURL); Where do I place this code? And lastly are the standard (and additional) headers added in the document headers section of IIs in the virtual directory that contains the asp.net form page? If not where? Thanks for your patience.

        Bruce K.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups