+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / 401 Unauthorized Error

401 Unauthorized Error

7 posts, 0 answered
  1. Michael
    Michael avatar
    4 posts
    Registered:
    08 Jan 2015
    25 Feb 2015
    Link to this post

    I have been assigned the task of researching the feasibility of using SiteFinity as a CMS for our current site's marketing department. I am testing things with the sample code I received from:

     

    http://www.sitefinity.com/blogs/svetlayankova/posts/svetla-yankovas-blog/2011/11/01/getting_started_with_restful_services_in_sitefinity

     

    When I run the code and give it the login information I get a 401 Unauthorized error.

    This is running with IISExpress.

    How do I get around this?

  2. Yavor Slavchev
    Yavor Slavchev avatar
    27 posts
    Registered:
    13 Sep 2016
    02 Mar 2015
    Link to this post
    Hello Michael,

    I think the referenced example is a bit outdated. You can refer to this example in GitHub in order to connect to Sitefinity properly. Note that you must select Claims authentication in order to connect successfully.

    I home this information is helpful. Do not hesitate to get back to us.

    Regards,
    Yavor Slavchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Michael
    Michael avatar
    4 posts
    Registered:
    08 Jan 2015
    02 Mar 2015 in reply to Yavor Slavchev
    Link to this post

    Thanks for the updated code, but I see some problems with the sample code you recently provided.

     1. It does not actually validate that the authentication was successful:

     

    private void Login_button_Click(object sender, EventArgs e)
            {   

                //set the credentials
                string sfUrl = this.url.Text;
                string username = this.username.Text;
                string password = this.password.Text;

                helper.SignIn(username, password, sfUrl);
                            
                DisableLogin();
                
            }

    The above simply makes the auth request and then enables the other buttons. 

     

    2. I do not think auth is working STILL because when I click the button "List data" I get an error:

     

    An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in System.Runtime.Serialization.dll

     

    This code causes that error: NewsItems rolesData = (NewsItems)rolesSerializer.ReadObject(ms);

     

     It appears that the object is empty which means auth failed.

    I am going to try a few things, but do you have any further tips?

  4. Atanas Valchev
    Atanas Valchev avatar
    414 posts
    Registered:
    04 Jan 2016
    05 Mar 2015
    Link to this post
    Hello,

    You can take a look at the second part of this blog post describing in details how this works with Claims Authentication used in the later Sitefinity versions:Working with RESTful Services Part 2 – Claims Authentication and Designing Service Calls.

    Regards,
    Atanas Valchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  5. Michael
    Michael avatar
    4 posts
    Registered:
    08 Jan 2015
    05 Mar 2015 in reply to Atanas Valchev
    Link to this post

    OK, so I can see that authentication works when I click the LOGIN on the sample application. However, what I have a problem with now is when I click on the button labelled "LIST DATA" I get an exception. Here is the code:

     

     private void ListNewsButtonClick(object sender, EventArgs e)
            {

                //Listing the roles
                string rolesResult = null;

                helper.CallService(ServiceHelper.NewsUrl, null, "GET", out rolesResult, "application/json");

                using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(rolesResult)))
                {
                    DataContractJsonSerializer rolesSerializer = new DataContractJsonSerializer(typeof(NewsItems));

                    NewsItems rolesData = (NewsItems)rolesSerializer.ReadObject(ms); <--- this line causes a n exception

                    foreach (NewsItem item in rolesData.Items)
                    {
                        NewsList.Items.Add(item);

                    }

                  

                }

      

            }

     

    The execption is system.runtime.serialization.serializationexception

     

    How do I get over this hurdle?

  6. Atanas Valchev
    Atanas Valchev avatar
    414 posts
    Registered:
    04 Jan 2016
    10 Mar 2015
    Link to this post
    Hello,

    I have tested the GitHub sample and I was not able to reproduce the error, video is attached. I would like to suggest opening a ticket for this issue so I can get more information regarding the exact scenario so I can investigate further.

    Regards,
    Atanas Valchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  7. Michael
    Michael avatar
    4 posts
    Registered:
    08 Jan 2015
    10 Mar 2015 in reply to Atanas Valchev
    Link to this post
    I already have a ticket open. It is thread id 910923.
7 posts, 0 answered