Sachin Singh

Sachin Singh

  • 7
  • 55.8k
  • 81.7k

IIS basic authentication with web api.

Aug 17 2020 11:07 AM
Believe me there is no solution given anywhere for this.
 
  1. I have created a web api project
  2. Enabled the Cors
  3. deployed the web api in iis 7.5
  4. Enabled Basic authentication (IIS Basic auth mode)
  5. Send an ajax request like below

  1. function getEmployee() {  
  2.        debugger;  
  3.        $.ajax({  
  4.            "type""get",  
  5.            "url""http://localhost:8080/api/employeeservice",  
  6.            "xhrFields": {  
  7.                "withCredentials"true  
  8.            },  
  9.            "dataTpe""Json",  
  10.            "headers": {  
  11.                 
  12.                'Authorization''Basic' + btoa('XYZ' + ":" + 'XYZ123')  
  13.            },  
  14.            "cache"false,  
  15.            "crossDomain"true,  
  16.            "success": function (data) {  
  17.   
  18.                $(data).each(function (i, y) {  
  19.                    var trr = document.createElement("tr");  
  20.                    $(trr).append("" + y.Id + "").append("" + y.Name + "").append("" + y.DOB + "").append("" + y.Salary + "").append("" + y.Gender + "");  
  21.                    $("table tbody").append(trr);  
  22.                });  
  23.   
  24.            },  
  25.              
  26.   
  27.   
  28.   
  29.   
  30.        })  
  31.    } 
 I have given my 3 hours of dedicated time to make this work , read all thread in StackOverflow but nothing worked.
 
Always getting the cors error even when Cors is enabled and works fine when i test with MVC or jqeuery (different port No) without hosting it on IIS.Only the authentication is creating chaos.
 
The first thing that may come to your mind is who uses the basic authentication and moreover IIS basic auth, obviously no one , but this is just for knowledge purpose.I am very curious when its a matter of any technology.
 
So please help me , otherwise it may take my whole week.
 

Answers (2)