God. Bless. America.
I spent half the day trying to debug an issue that was infuriating. Here is the background. I have an MVC 4 .net 4.0 web application that uses a bunch of JQuery calls to controllers and stores data locally using the HTML 5 SessionStorage object. My site works ‘perfectly’ in every browser when debugging locally. When I published to an IIS 7.5 Windows Server 2008 R2 server, everything still worked wonderfully. Only… I didn’t test the site again in Safari after I published it to production. Because why would I use Safari for real browsing ;P Low and behold, I got a call from one of our clients saying the site didn’t work in Safari. Grr… And I was so close to actually getting some real work done today.
5 hours later, I’ve worked through my lunch trying to track this down. Using Safari’s (actually decent) developer tools, I could see that the function I was calling from an ‘OnClick(this)’ command was being called appropriately. The function pulled my SessionStorage object from storage and stored it as a string in a local variable just fine. Then my .post(url, parameters, function(data) { }); looked good! The two parameters I specified had the appropriate data displaying when I hovered over it in the Safari JavaScript debugger. I would step into the next call and the debugger would skip over the success function. Sure enough, I checked my logs from the server and I got ‘null reference’ errors from the Controller method that JavaScript function called.
I tried at least 30 different solutions, including stepping back my JQuery version (which actually helped somewhat but introduced another 5 problems I didn’t feel like tackling). What bothered me the whole time is that I have windows authentication enabled on my IIS server. No forms authentication enabled. And in Safari, I never got prompted for a password. I looked everywhere for a setting in Safari that didn’t auto-submit my network credentials, but couldn’t find one. And the solution was related to that.
The Solution: On the bottom of a stack-overflow page was a post that nobody cared about from a guy who didn’t have his problem solved by the accepted answer above. He found the issue to be a bug with Safari and Windows Authentication Providers. Specifically, the Negotiate provider for Windows Authentication. He disabled that provider and that fixed his problem. It fixed mine too :-) I disabled Negotiate under Windows Authentication Providers in IIS and suddenly I was prompted for a password when I tried to login to my site in Safari. Sure enough, all of my JQuery calls started working.
Here is a link to the article that saved my day: http://stackoverflow.com/questions/15017412/safari-posting-blank-form-to-my-server/15926177#15926177
I gave that guy a +1 because he deserved it. Thanks Jeff Johnson!
Here are the step-by-step instructions to fix this issue yourself if you’re experiencing the same symptoms Jeff and I did:
- Open IIS on your webserver hosting the site having the problem.
- Left click on the site in question.
- Double click “Authentication” under the IIS sub-heading.
- Right click “Windows Authentication” and select “Providers”.
- Select “Negotiate” and remove it.
- Recycle your app pool for that site.
Capt. Rochefort (If at first you don’t succeed, use your wordsmithing skills to get a better response from Google)
Filed under: .net, Ajax, C#, HTML 5, IIS 7.5, JQuery, MVC4 Tagged: .Post, Ajax, IIS, IIS 7.0, IIS 7.5, JQuery, Login, Negotiate, Null, Null Parameter, Parameters, Safari, Windows 2008 R2, Windows Server 2008
