【发布时间】:2014-03-01 07:05:37
【问题描述】:
在我的网站中,我使用 Add Service Reference ,阅读了一些 SharePoint 列表, 第一次打开电脑,VS出现错误!!! 之后它就可以工作了,当我想在我的 IIS 或服务器 ISS 上尝试时,会发生同样的错误并且没有修复:
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
来源错误:
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.
堆栈跟踪:
[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.DataServiceQuery`1.Execute() +113
System.Data.Services.Client.DataServiceQuery`1.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
这个错误发生在我想从 SharePoint 列表中读取数据的 foreach 循环中!
我能做什么!?
这是我的代码,在页面加载中添加服务引用之后:
ServiceReference1.TPPDataContext obj = new ServiceReference1.TPPDataContext(new Uri("http://sharepoint/_layouts/viewlsts.aspx/_vti_bin/ListData.svc"));
obj.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
var sourc = obj.Announcement;
foreach (var item in sourc)
{
if (item.WF1 == "Management1" && item.AnnounceTypeValue == "Management")
{
Place[0] = item.Text1;
}
else if (item.WF1 == "Sharepoint1" && item.AnnounceTypeValue == "Sharepoint")
{
Place[1] = item.Text1;
}
else if (item.WF1 == "Admin1" && item.AnnounceTypeValue == "Admin")
{
Place[2] = item.Text1;
}
else if (item.WF1 == "Training1" && item.AnnounceTypeValue == "Training")
{
Place[3] = item.Text1;
}
else if (item.WF1 == "Others1" && item.AnnounceTypeValue == "Others")
{
Place[4] = item.Text1;
}
}
【问题讨论】:
-
好吧,显然运行您的 Web 应用程序的上下文的用户帐户没有 SharePoint 的权限。
标签: c# asp.net wcf sharepoint iis