Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Galina 44 posts 258 karma points
    Apr 01, 2015 @ 13:57
    Galina
    0

    Call asmx: 401 Unauthorized

    Hello,

    I use thirt-party component which need to call asmx webservice. That is why I need to use asmx not webapi.

    There is an 401 Unauthorized error. For testing I've created

    /json/menuextended.asmx

    namespace UmbracoCMS.json
    {
    [WebService(Namespace = "UmbracoCMS.json")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ScriptService]
    public class menuextended : WebService
    {
    [WebMethod(EnableSession = true)]
    [ScriptMethod]
    public string loadmenu()
    {
    return "1111";
    }
    }
    }
    and on masterpage (it's a webforms project) call:
    <script type="text/javascript">
        $(document).ready(function() {
                $.ajax({
                    type: "GET",
                    url: "/json/menuextended.asmx/loadmenu",
                    contentType: "application/json", 
                    dataType: "json",
                    success:function (data){
                        alert("ok");
            },
                    error: function (data){
                        alert("error");
                    }
            });
        });
    </script>

    I've got an error 401 Unauthorized. When I used UmbracoAuthorizedWebService and UmbracoWebService situation was the same. Where is the mistake?

  • Galina 44 posts 258 karma points
    Apr 01, 2015 @ 14:10
    Galina
    0

    If I call it by link http://localhost:29000/json/menuextended.asmx/loadmenu everythink is ok

  • Galina 44 posts 258 karma points
    Apr 01, 2015 @ 15:59
    Galina
    100

    Ok, additional info: we use cluster for Umbraco backoffice. And I wrote to web.config

    <sessionState cookieless="true" mode="StateServer" stateConnectionString="tcpip=job.trunk.ozon:42424" timeout="60" useHostingIdentity="false"/>

     

    cookieless="true" -- because without of this parameter angular.js didn't send cookie to server and Umbraco thought that it was unauthenticated user. But ajax-call can't redirect from http://localhost:29000/json/menuextended.asmx/loadmenu  to http://localhost:29000/(SessionID)/json/menuextended.asmx/loadmenu  and show me "401 unauthorized" . If I return cookieless="false" everythink work ok. In my case the decision was: 

    If you use ajax jquery post call with contentType: "application/json" don't use cookieless="true" for backofiice state server.

Please Sign in or register to post replies

Write your reply to:

Draft