我在Visual Studio中的网站运行良好,但在IIS上没有?

时间:2014-03-01 07:05:37

标签: c# asp.net wcf sharepoint iis

在我的网站中,我使用添加服务参考,我阅读了一些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

此错误发生在foreach循环上,我想从SharePoint列表中读取数据!

我能做什么!?

这是我的代码,在页面加载后添加服务引用:

    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;
        }
    }

1 个答案:

答案 0 :(得分:0)

可能它不起作用,因为IIS上的应用程序在IIS用户下运行或者设置为匿名用户。你可以尝试两件事:

  1. 如果您的用户有权限,请尝试将IIS中的应用设置为集成身份验证。

  2. (或)设置具有SharePoint权限的用户,而不是DefaultCredentials:

    obj.Credentials = new System.Net.NetworkCredential(“user”,                                                 “密码”,                                                 “结构域”);