Web 部件错误:(401) 未经授权

发布于 2024-11-15 12:18:06 字数 6912 浏览 1 评论 0原文

我有一个小程序,用于查询 Web 服务、使用 XSLT 转换结果并将其显示在 jQuery 控件中。当我将代码移动到 Web 部件中并部署它时,我收到以下错误:

The remote server returned an error: (401) Unauthorized.

这是加载我的 XSLT 文件的代码,这就是我怀疑问题所在的地方:

XPathDocument xPathDoc;
XsltArgumentList args;

protected override void OnPreRender(EventArgs e)
{
  xPathDoc = QueryRunner.GetQueryResults();
  args = QueryRunner.GetColumnsToShow();
}

public static XPathDocument GetQueryResults()
{
  OpacAccess.OpacAccess proxy = new OpacAccess.OpacAccess();

  string result = string.Empty;

  try
  {
     result = proxy.query("CompanyName", "username", "password", 
         ReadingList=\"London\"", 1000);
  }
  catch (Exception ex)
  {
  }

  // Store the xml of the result
  XPathDocument xPathDoc = new XPathDocument(new StringReader(result));

  return xPathDoc;
}   

protected override void RenderContents(HtmlTextWriter output)
{
  XslTransform xslt = new XslTransform();

  // Load the xslt file and perform the transformation
  xslt.Load("http://rginfonet/Style%20Library/XSL%20Style%20Sheets/Liberty.xslt");
  xslt.Transform(xPathDoc, args, output, null);
  output.Flush();
}

这是我的堆栈跟踪(如果有的话)对任何人都有帮助:

[WebException:远程服务器返回错误:(401)未经授权。] System.Net.HttpWebRequest.GetResponse()+5375213 System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri,ICredentials 凭据)+69 System.Xml.XmlDownloadManager.GetStream(Uri uri,ICredentials 凭据)+3929371 System.Xml.XmlUrlResolver.GetEntity(Uri 绝对Uri,字符串角色,ObjectToReturn 类型)+ 54 System.Xml.XmlTextReaderImpl.OpenUrlDelegate(对象 xmlResolver) +74 System.Threading.CompressedStack.runTryCode(对象 userData) +70 System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode 代码、CleanupCode backoutCode、对象 userData) +0 System.Threading .compressedstack.run(compressedstackcompressedStack,ContextCallback回调,对象状态) +108 System.Xml.XmlTextReaderImpl.OpenUrl() +186 System.Xml.XmlTextReaderImpl.Read() +208 System.Xml.XPath.XPathDocument.LoadFromReader(XmlReader 阅读器,XmlSpace 空间) +217 System.Xml .XPath.XPathDocument..ctor(XmlReader 阅读器, XmlSpace 空间) +20 System.Xml.Xsl.XsltOld.Compiler.LoadDocument(XmlTextReaderImpl 阅读器) +85 System.Xml.Xsl.XslTransform.Load(字符串 url,XmlResolver 解析器) +100 System.Xml.Xsl.XslTransform.Load(字符串 url)+25 LibertyControl.ResultsGrid.RenderContents(HtmlTextWriter 输出)+74 System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter编写器)+32 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter编写器,ControlAdapter适配器)+27 System.Web.UI.Control.RenderControl(HtmlTextWriter编写器,ControlAdapter适配器) ) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,ICollection 子级) +134 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19 System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter writer) +10 System.Web.UI.WebControls.WebControl.Render (HtmlTextWriter 编写器)+32 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter 编写器,ControlAdapter 适配器)+27 System.Web.UI.Control.RenderControl(HtmlTextWriter 编写器、ControlAdapter 适配器) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter 编写器) +25 Microsoft.SharePoint.WebPartPages.SPChrome.RenderPartContents(HtmlTextWriter 输出、WebPart 部分)+ 66

[WebPartException:远程服务器返回错误:(401) 未经授权。] Microsoft.SharePoint.WebPartPages.SPChrome.RenderPartContents(HtmlTextWriter 输出,WebPart 部分) +140 Microsoft.SharePoint.WebPartPages.SPChrome.RenderWebPart(HtmlTextWriter 输出,WebPart 部分) +63 Microsoft.SharePoint.WebPartPages.WebPartZone.RenderZoneCell(HtmlTextWriter 输出,布尔值) bMoreParts、WebPart 部分)+144 Microsoft.SharePoint.WebPartPages.WebPartZone.RenderWebParts(HtmlTextWriter 输出、ArrayList webParts) +495 Microsoft.SharePoint.WebPartPages.WebPartZone.Render(HtmlTextWriter 输出) +902 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter 编写器、ControlAdapter 适配器)+ 27 System.Web.UI.Control.RenderControl(HtmlTextWriter编写器,ControlAdapter适配器)+99 System.Web.UI.Control.RenderControl(HtmlTextWriter 编写器) +25 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter 编写器,ICollection 子级) +134 System.Web.UI.Control.RenderChildren(HtmlTextWriter 编写器) +19 System. Web.UI.Control.Render(HtmlTextWriter编写器)+10 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter编写器,ControlAdapter适配器) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter 编写器,ControlAdapter 适配器) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter 编写器) +25 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter 编写器, ICollection 子级)+134 System.Web.UI.Control.RenderChildren(HtmlTextWriter 编写器)+19 System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter编写器) +32 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter编写器,ControlAdapter适配器) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter编写器,ControlAdapter适配器) ) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter 编写器) +25 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter编写器,ICollection子级)+134 System.Web.UI.Control.RenderChildren(HtmlTextWriter编写器)+19 System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter编写器)+163 System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter编写器)+32 System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter输出)+51 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter编写器,ControlAdapter适配器)+27 System.Web.UI.Control.RenderControl(HtmlTextWriter编写器,ControlAdapter适配器) ) +99 System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter 编写器) +40 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter编写器,ICollection子级)+134 System.Web.UI.Control.RenderChildren(HtmlTextWriter编写器)+19 System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter编写器)+32 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter编写器,ControlAdapter适配器)+27 System.Web.UI.Control.RenderControl(HtmlTextWriter 编写器,ControlAdapter 适配器) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter 编写器) +25 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter 编写器,ICollection 子级)+ 134 System.Web.UI.Control.RenderChildren(HtmlTextWriter 编写器) +19 System.Web.UI.Control.Render(HtmlTextWriter 编写器) +10 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter 编写器,ControlAdapter 适配器) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter 编写器,ControlAdapter 适配器) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter 编写器) )+25 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter 编写器,ICollection 子级)+134 System.Web.UI.Control.RenderChildren(HtmlTextWriter编写器)+19 System.Web.UI.Page.Render(HtmlTextWriter编写器)+29 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter编写器,ControlAdapter适配器)+27 System. Web.UI.Control.RenderControl(HtmlTextWriter 编写器,ControlAdapter 适配器)+99 System.Web.UI.Control.RenderControl(HtmlTextWriter 编写器)+25 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266

如果您能提供一些关于导致此问题的原因的见解,请告诉我。谢谢!

I have a little program that queries a web service, transforms the results using XSLT and displays them in a jQuery control. When I move the code into a web part it and deploy it, however I'm getting the following error:

The remote server returned an error: (401) Unauthorized.

This is the code that's loading my XSLT file, which is where I suspect the problem is:

XPathDocument xPathDoc;
XsltArgumentList args;

protected override void OnPreRender(EventArgs e)
{
  xPathDoc = QueryRunner.GetQueryResults();
  args = QueryRunner.GetColumnsToShow();
}

public static XPathDocument GetQueryResults()
{
  OpacAccess.OpacAccess proxy = new OpacAccess.OpacAccess();

  string result = string.Empty;

  try
  {
     result = proxy.query("CompanyName", "username", "password", 
         ReadingList=\"London\"", 1000);
  }
  catch (Exception ex)
  {
  }

  // Store the xml of the result
  XPathDocument xPathDoc = new XPathDocument(new StringReader(result));

  return xPathDoc;
}   

protected override void RenderContents(HtmlTextWriter output)
{
  XslTransform xslt = new XslTransform();

  // Load the xslt file and perform the transformation
  xslt.Load("http://rginfonet/Style%20Library/XSL%20Style%20Sheets/Liberty.xslt");
  xslt.Transform(xPathDoc, args, output, null);
  output.Flush();
}

Here's my stack trace if it's at all helpful to anyone:

[WebException: The remote server returned an error: (401) Unauthorized.] System.Net.HttpWebRequest.GetResponse() +5375213 System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials) +69 System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials) +3929371 System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) +54 System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver) +74 System.Threading.CompressedStack.runTryCode(Object userData) +70 System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) +0 System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state) +108 System.Xml.XmlTextReaderImpl.OpenUrl() +186 System.Xml.XmlTextReaderImpl.Read() +208 System.Xml.XPath.XPathDocument.LoadFromReader(XmlReader reader, XmlSpace space) +217 System.Xml.XPath.XPathDocument..ctor(XmlReader reader, XmlSpace space) +20 System.Xml.Xsl.XsltOld.Compiler.LoadDocument(XmlTextReaderImpl reader) +85 System.Xml.Xsl.XslTransform.Load(String url, XmlResolver resolver) +100 System.Xml.Xsl.XslTransform.Load(String url) +25 LibertyControl.ResultsGrid.RenderContents(HtmlTextWriter output) +74 System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +32 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19 System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter writer) +10 System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +32 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 Microsoft.SharePoint.WebPartPages.SPChrome.RenderPartContents(HtmlTextWriter output, WebPart part) +66

[WebPartException: The remote server returned an error: (401) Unauthorized.] Microsoft.SharePoint.WebPartPages.SPChrome.RenderPartContents(HtmlTextWriter output, WebPart part) +140 Microsoft.SharePoint.WebPartPages.SPChrome.RenderWebPart(HtmlTextWriter output, WebPart part) +63 Microsoft.SharePoint.WebPartPages.WebPartZone.RenderZoneCell(HtmlTextWriter output, Boolean bMoreParts, WebPart part) +144 Microsoft.SharePoint.WebPartPages.WebPartZone.RenderWebParts(HtmlTextWriter output, ArrayList webParts) +495 Microsoft.SharePoint.WebPartPages.WebPartZone.Render(HtmlTextWriter output) +902 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19 System.Web.UI.Control.Render(HtmlTextWriter writer) +10 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19 System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19 System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +163 System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32 System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +51 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99 System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +40 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19 System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19 System.Web.UI.Control.Render(HtmlTextWriter writer) +10 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19 System.Web.UI.Page.Render(HtmlTextWriter writer) +29 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266

Please let me know if you can lend some insight to what's causing this. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静若繁花 2024-11-22 12:18:06

负责呈现 Web 部件的帐户无权访问 xslt 所在的文档库。

有几种方法可以解决这个问题,

  1. 授予系统帐户访问该库的权限
  2. 使用模拟
  3. 如果 xslt 不会改变那么多,那么将其包含为 Web 部件的资源

The account responsible for rendering the webpart does not have access to the document library where you have the xslt located.

There are a few ways to get around this,

  1. Give permissions to the system account to access that library
  2. Use impersonation
  3. If the xslt won't change that much then include it as a resource of the webpart
拍不死你 2024-11-22 12:18:06

如果您将 Web 部件部署在 bin 文件夹中,则该文件夹可能没有权限,无法向您显示 Web 部件。添加足够的权限。

If you deployed your webpart in the bin folder ,might be that folder won't have permissions and not able to show you the webpart.Add sufficient permissions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文