zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    20121025
    活到老学到老
    VS2012 正式版BUG太多
    JSP页面basePath路径问题
    这样的日子
    正确用JQ的AJAX加载XML并解析
    JSP中的5中转发方式
    C#编码规范
    jsp判断用户是否在线
    beging
  • 原文地址:https://www.cnblogs.com/happy-Chen/p/3666224.html
Copyright © 2011-2022 走看看