jquery ajax calls to asp.net web methods authentication error

I discovered this by creating the application again from scratch thanks to this other site: http://blogs.msdn.com/b/webdev/archive/2013/12/19/building-a-basic-web-forms-application-using-visual-studio-2013.aspx . By following each step carefully and experimenting with the code I realized that when I added the friendly urls framework and enabled Bundling and Minification my jquery ajax call failed. This allowed me ask the correct question to google and I found out that the problem lied in the following files:

1) ~/App_Start/RouteConfig.cs.

    The followint line of code in this file must be changed:

    Fromsettings.AutoRedirectMode =RedirectMode.Permanent;

    Tosettings.AutoRedirectMode = RedirectMode.Off;

 The other alternative is to simply comment it:  

  //settings.AutoRedirectMode =RedirectMode.Permanent;

2) By having friendly URLs enabled, it is necessary to change the way to call the web method, especifically its route:

   From ‘userForm.aspx/getAllUsers‘

   To‘<%= ResolveUrl("userForm.aspx/getAllUsers") %>‘

So that the final jQuery code looks like this:

      $.ajax({         url: ‘<%= ResolveUrl("userForm.aspx/getAllUsers") %>‘,         async: false,         contentType: ‘application/json; charset=utf-8‘,         success: function (data) {           source.localdata = data.d;         },         error: function (err) {           alert(‘Error: ‘ + err);         }       })

With this issue fixed now my app works fine.

jquery ajax calls to asp.net web methods authentication error,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。