39265

jquery ajax call fails with 401 unauthorized

Question:

I have a jquery ajax POST to a code-behind webmethod. In that webmethod i do a HttpWebRequest to a third party web api service that returns json. Even though the httpwebrequest works fine, a popup appears in the browser asking me to enter credentials (authentication required). On my machine this works well, however when deployed it doesn't except if there is no data returned from the httpwebrequest call.

The jquery call:

function serverCall(httpMethod, pageName, methodName, inputData, successCallback, errorCallback, disableGlobalAjaxEvents) { // Construct the url var url = pageName + "/" + methodName; var triggerGlobalEvents = true; if (disableGlobalAjaxEvents && disableGlobalAjaxEvents == true) { triggerGlobalEvents = false; } $.ajax({ type: httpMethod, url: url, data: JSON.stringify(inputData), contentType: "application/json; charset=utf-8", global: triggerGlobalEvents, dataType: "json", success: function(msg) { if (successCallback) { var parsedObject = JSON.parse(msg.d); successCallback(parsedObject); } }, error: function(error, status) { if (errorCallback) { errorCallback(error, status); } } });

And here is the actual call:

serverCall("POST", "SomePage.aspx", "GetSomething", inpuData, onSuccess, onError, true);

The webmethod:

[WebMethod( CacheDuration = 5, EnableSession = true)] public static string GetSomething(string user, string item) { // In the body i do the HTTPWebRequest that returns JSON }

Answer1:

Ok, problem is solved. It wasn't a security issue after all but a serialization issue. In the webmethod i stored the received object (via HttpWebRequest) in the ASP.NET Session. When deployed, the session is stored in a db and hence the serialization problem. On my machine I used inproc session, that is why it worked on my machine.

Recommend

  • WorkLighr 6.0 Deployement on windows 8 issue
  • How to overcome dimension mismatch for writing to a CSV file in MATLAB?
  • Recreating Python's input statement in Swift
  • How to use the Watson Conversation inside iOS Swift?
  • using HttpHandlerFactory to render CMS and physical pages
  • how to increase size of post parameter list
  • How to get Job parameteres in to item processor using spring Batch annotation
  • Mod_rewrite .htm to fake subdirectory
  • where should i encode this html data in an asp.net mvc site
  • Structure of async callbacks in javascript: Synching the Asynch
  • Send array of objects via GET request with Angular's $http to Java Spring
  • Backbone Router on any page change event
  • Setting null for single-valued navigation property using Xrm.WebApi
  • Binding a method to a column in datagrid WPF
  • Getting a Template/Generic java.lang.reflect.Method object from org.aspectj.lang.ProceedingJoinPoint
  • How to download an image using Java Socket from a remote Http server?
  • Update property from interface
  • AngularJs. $http post not posting all the items to a collection in a for loop
  • How to create c# console application to cosume the .net webservice [closed]
  • Can you allocate a buffer that is larger than the device memory using opencl on a GPU
  • How to set THTTPRio.Converter.Options to soLiteralParams in OnBeforeExecuteEvent
  • Prevent redirect response with Alamofire in Swift
  • Eclipse doesn't generate google cloud endpoint client library
  • MVC6 Cors - intercept preflight
  • Html.BeginRouteForm doesn't generate URL for named route
  • Uploading image with other parameters in SWIFT
  • Counter field in MS Access, how to generate?
  • Is there a amazon webstore API for customers?
  • Can Jackson SerializationFeature be overridden per field or class?
  • How to extract text from Word files using C#?
  • vba code to select only visible cells in specific column except heading
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • KeystoneJS: Relationships in Admin UI not updating
  • trying to dynamically update Highchart column chart but series undefined
  • embed rChart in Markdown
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app