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.

转载于:https://www.cnblogs.com/happy-Chen/p/3666224.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值