首页 > Web开发 > 详细

jquery ajax calls to asp.net web methods authentication error

时间:2014-04-16 05:34:46      阅读:556      评论:0      收藏:0      [点我收藏+]

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,布布扣,bubuko.com

jquery ajax calls to asp.net web methods authentication error

原文:http://www.cnblogs.com/happy-Chen/p/3666224.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!