2015-04-28 39 views
6

Quando faccio una chiamata JQuery, ottengo un Autenticazione non riuscita risposta:

{ 
    Message: "Authentication failed.", 
    StackTrace: null, 
    ExceptionType: "System.InvalidOperationException" 
} 

jQuery chiamata:

$(document).ready(function() { 
    //Handle the change event for the drop down list 
    $("#ddRegions").change(function() { 
     //create the ajax request 
     $.ajax({ 
      type: "POST", //HTTP method 
      url: '<%= ResolveUrl("WebForm2.aspx/getLocations")%>', //page/method name 
      data: "{}", //json to represent argument 
      contentType: "application/json; charset=utf-8", 
      dataType: "json", 
      success: function (msg) { //handle the callback to handle response     
       //request was successful. so Retrieve the values in the response. 
       alert(msg.toSource()); 
      } 
     }); 
    }); 
}); 

il metodo Web:

public static string getLocations() { 
    System.Diagnostics.Debug.WriteLine("Getting Locations."); 
    return "{region:auckland, city:auckland}"; 
} 

ho aggiunto il seguente al mio web.config:

<authorization> 
    <allow users="*" /> 
</authorization> 
<authentication mode="None" /> 

E ho provato a impostare lo AutoRedirectMode su Off in RouteConfig.cs. Questo arresta l'errore, ma il metodo web non viene mai chiamato. Eventuali suggerimenti?

+1

hai provato usando $ .support.cors = true; in jQuery per abilitare l'origine incrociata questo è limitato dai browser per scopi di sicurezza? –

+0

Quando dici che non viene mai chiamato, il browser invia la richiesta? In tal caso, puoi mostrare la risposta e la richiesta utilizzando Fiddler o gli Strumenti per gli sviluppatori di Google Chrome? –

+0

Questo può aiutarti? http://forums.asp.net/t/1975897.aspx?jquery+ajax+calls+to+asp++++++++++++++++++++++++++++++++++++++++++++ –

risposta

4

risolto impostando AutoDirectMode Off nel App_Start/RouteConfig.cs

settings.AutoRedirectMode = RedirectMode.Off; 

e l'aggiunta di uno ScriptManager alla pagina aspx che ha un EnablePageMethods impostate su 'vero':

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True"> 
    </asp:ScriptManager> 
Problemi correlati