401 Unauthorized Error
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:
www.sitefinity.com/.../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?
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
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?
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
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?
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
I already have a ticket open. It is thread id 910923.