Note that there are some explanatory texts on larger screens.

plurals
  1. POIE 10 HTTP 401 Error on ajax POST
    text
    copied!<p><a href="https://stackoverflow.com/questions/15210158/401-using-multiple-authentication-methods-ie-10-only">I've been chasing down an issue</a> and decided to make the most basic reproduction of the issue possible in hopes that a simplified question will help me resolve this.</p> <p>I am receiving a 401 when posting to a web service via ajax in javascript. I will include as much information as well as all of the troubleshooting steps I have tried.</p> <p>I created a test page on the root of my site and tried both plain JS and jquery for the ajax call with the same results. I've included the jquery commented out...</p> <p><strong>Page</strong> </p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;head&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; /*$(document).ready(function() { $('#button').click(function() { var ID = 2; var firstname = $('#First_Name').val(); var lastname = $('#Last_Name').val(); $.ajax({ type: 'POST', url: '/service/name/service.aspx/ChangeName', contentType: 'application/json; charset=utf-8', dataType: 'json', data: '{ "ID": "' + ID + '", "firstName": "' + firstname + '", "lastName": "' + lastname + '" }', success: function() { console.log('success'); }, error: function(d) { console.log(d.responseText); } }); }); });*/ function runAjax() { //Create Http request depending on browser var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest();} else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");} xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200){ document.getElementById("myDiv").innerHTML=xmlhttp.responseText;} } // Function to create var url = "/service/name/service.aspx/ChangeName"; xmlhttp.open("POST",url,true); xmlhttp.setRequestHeader("Content-Type", "application/json; charset=utf-8"); var data=JSON.stringify({ "ID": "2", "firstName": "John", "lastName": "Doe" }); xmlhttp.send(data); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="myDiv"&gt; &lt;table width="100%" cellpadding="3" cellspacing="0"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td width="34%"&gt; &lt;div align="right"&gt; &lt;strong&gt;First Name: &lt;/strong&gt; &lt;/div&gt; &lt;/td&gt; &lt;td&gt; &lt;div&gt; &lt;input name="First_Name" type="text"id="First_Name" size="20"&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;div align="right"&gt; &lt;strong&gt;Last Name: &lt;/strong&gt; &lt;/div&gt; &lt;/td&gt; &lt;td&gt; &lt;input name="Last_Name" type="text" id="Last_Name" size="20"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;div align="center"&gt; &lt;input id="button" type="button" value="Update Student Details" onclick="runAjax();" style="margin:5px;"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Now in every browser except for IE10 this works fine. In fiddler it shows that IE is getting a 401 response</p> <p><strong>Request Headers</strong> <em>fiddler</em></p> <pre><code>POST http://dev.mysite/service/name/service.aspx/ChangeName HTTP/1.1 Accept: */* Content-Type: application/json; charset=utf-8 Referer: http://dev.mysite/test_page.html Accept-Language: en-US Accept-Encoding: gzip, deflate User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0) Connection: Keep-Alive Content-Length: 46 DNT: 1 Host: dev.mysite Pragma: no-cache {"ID":"2","firstName":"John","lastName":"Doe"} </code></pre> <p><strong>Response Headers</strong> <em>fiddler</em></p> <pre><code>HTTP/1.1 401 Unauthorized Content-Type: application/json; charset=utf-8 Server: Microsoft-IIS/7.0 jsonerror: true WWW-Authenticate: Negotiate WWW-Authenticate: NTLM X-Powered-By: ASP.NET Date: Thu, 07 Mar 2013 01:12:05 GMT Content-Length: 105 Proxy-Support: Session-Based-Authentication </code></pre> <p>I enabled Failed Request Tracing on the server and this is the information it gives me for that call:</p> <p><strong>Failed Request Log</strong> <em>iis</em></p> <p><strong>1. -GENERAL_REQUEST_START</strong></p> <ul> <li><em>SiteId</em> - 2 </li> <li><em>AppPoolId</em> - ASP.NET v4.0 </li> <li><em>ConnId</em> - 1610622306 </li> <li><em>RawConnId</em> - 0 </li> <li><em>RequestURL</em> - <a href="http://dev.mysite:80/service/name/service.aspx/ChangeName" rel="nofollow noreferrer">http://dev.mysite:80/service/name/service.aspx/ChangeName</a></li> <li><em>RequestVerb</em> - POST </li> </ul> <p><strong>2. -FILTER_START</strong></p> <ul> <li><em>FilterName</em> - C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_filter.dll </li> </ul> <p><strong>3. -FILTER_END</strong></p> <p><strong>4. -AspNetStart</strong></p> <ul> <li><em>ConnID</em> - 0 </li> <li><em>Context ID</em> - {00000000-0000-0000-6425-0080000000BF} </li> <li><em>Data1</em> - POST </li> <li><em>Data2</em> - /service/name/service.aspx </li> <li><em>Data3</em> - </li> </ul> <p><strong>5. -GENERAL_REQUEST_END</strong></p> <ul> <li><em>BytesSent</em> - 359 </li> <li><em>BytesReceived</em> - 440 </li> <li><em>HttpStatus</em> - 401 </li> <li><em>HttpSubStatus</em> - 0 </li> </ul> <p>Things I found by simplifying the ajax request was that it is not only a Windows 8 problem and that turning compatibility mode on does not work either.</p> <p>I have tried disabling the Kernel-mode authentication in IIS, I've triple checked permissions on the web service folder, <a href="https://serverfault.com/questions/484657/401-using-multiple-authentication-methods-ie-10-only/484677?noredirect=1#484677">followed these suggestions</a>, I've even tried placing the web service in the same directory as the page. All with the same result... Any direction or assistance is greatly appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload