Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
In my website I use Add Reference , I read some SharePoint lists, For the first time I turn on my computer , in VS an error occur !!! After that it works , and when I want to try on my IIS or Server ISS , the same error occur and did not fix :

C#
Server Error in '/' Application. Unauthorized Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.Services.Client.DataServiceClientException: Unauthorized

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[DataServiceClientException: Unauthorized] System.Data.Services.Client.QueryResult.Execute() +656 System.Data.Services.Client.DataServiceRequest.Execute(DataServiceContext context, QueryComponents queryComponents) +349

[DataServiceQueryException: An error occurred while processing this request.] System.Data.Services.Client.DataServiceRequest.Execute(DataServiceContext context, QueryComponents queryComponents) +562697 System.Data.Services.Client.DataServiceQuery1.Execute() +113
   System.Data.Services.Client.DataServiceQuery1.GetEnumerator() +22 _default.Page_Load(Object sender, EventArgs e) in c:\Users\user\Desktop\TPPG\tppg.com\default.aspx.cs:58 System.Web.UI.Control.LoadRecursive() +71 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3178


And this error occur on foreach loop where I want to read data from SharePoint lists !

what can I do !?
Posted
Updated 28-Feb-14 20:41pm
v2
Comments
Maarten Kools 1-Mar-14 3:29am    
When running your website in IIS it's associated with an Application Pool. By default this runs under ApplicationPoolIdentity. Try running the Application Pool using a different user (as you would do when running from Visual Studio). See here[^] for more details on how to set it.
Member 10481338 1-Mar-14 4:45am    
I tried 3 other options, but it did not work !
ZurdoDev 1-Mar-14 7:55am    
It says Unauthorized which means you have a security issue somewhere.
Member 10481338 2-Mar-14 0:48am    
thank you , but where and how solve it !?
ZurdoDev 2-Mar-14 20:21pm    
You'll have to figure that out. I don't have access to your setup.

1 solution

I am assuming you are using SharePoint client object model to query the data from SharePoint list.

You might have to pass the credentials to the client context.Check if the below code works!

C#
if (isForms)
{
    context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
    FormsAuthenticationLoginInfo fba = new FormsAuthenticationLoginInfo(userName, password);
    context.FormsAuthenticationLoginInfo = fba;
}
else
{
    context.Credentials = new NetworkCredential(userName, password);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900