我正在尝试在 Sharepoint MOSS 2007 自定义 Web 部件中加载 XSLT 文件,但在尝试访问 XSLT 文件时出现 401 错误。我尝试提供默认凭据,但在调试期间检查时它是空的。
有谁知道如何从自定义 Web 部件加载 XSLT 文件?提前致谢。
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = CredentialCache.DefaultNetworkCredentials;
XsltSettings settings = new XsltSettings(true, true);
XslCompiledTransform oXSLTranform = new XslCompiledTransform();
string siteUrl = SPContext.Current.Site.Url;
if (siteUrl.EndsWith("/"))
siteUrl = siteUrl.Remove(siteUrl.LastIndexOf("/"));
siteUrl += "/Style Library/XSL Style Sheets/THM1News.xslt";
oXSLTranform.Load(siteUrl ,settings, resolver);
此代码返回 401 错误:
远程服务器返回错误:(401) Unauthorized。
[WebException: 远程服务器返回错误:(401) Unauthorized.] System.Net.HttpWebRequest.GetResponse() +5313085 System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials) +69 System.Xml.XmlDownloadManager.GetStream (Uri uri,ICredentials 凭据)+3929007 System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri,字符串角色,Type ofObjectToReturn)+54 System.Xml.Xsl.Xslt.XsltLoader.CreateReader(Uri uri,XmlResolver xmlResolver)+26 System. Xml.Xsl.Xslt.XsltLoader.Load(编译器编译器,对象样式表,XmlResolver xmlResolver)+315 System.Xml.Xsl.Xslt.Compiler.Compile(对象样式表,XmlResolver xmlResolver,QilExpression&qil)+41 System.Xml.Xsl。 XslCompiledTransform.CompileXsltToQil(对象样式表,XsltSettings 设置,XmlResolver stylesheetResolver)+59 System.Xml.Xsl。XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) +66 System.Xml.Xsl.XslCompiledTransform.Load(String stylesheetUri, XsltSettings settings, XmlResolver stylesheetResolver) +38 NewsGallery.AjaxNewsWebPart.AjaxNewsControl.RenderContents(HtmlTextWriter output) +403 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 children) +134 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19 System.Web.UI.WebControls.WebControl。RenderContents(HtmlTextWriter 编写器)+10 System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter 编写器)+32 Microsoft.SharePoint.WebPartPages.WebPart.RenderWebPart(HtmlTextWriter 输出)+36 Microsoft.SharePoint.WebPartPages.WebPart.RenderWebPartInternal(HtmlTextWriter编写器)+139 Microsoft.SharePoint.WebPartPages.WebPart.Render(HtmlTextWriter 编写器)+93 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter 编写器,ControlAdapter 适配器)+27 System.Web.UI.Control.RenderControl(HtmlTextWriter 编写器, ControlAdapter 适配器)+99 System.Web.UI.Control.RenderControl(HtmlTextWriter writer)+25 Microsoft.SharePoint.WebPartPages.SPChrome.RenderPartContents(HtmlTextWriter 输出,WebPart 部分)+66渲染(HtmlTextWriter 编写器)+32 Microsoft.SharePoint.WebPartPages.WebPart.RenderWebPart(HtmlTextWriter 输出)+36 Microsoft.SharePoint.WebPartPages.WebPart.RenderWebPartInternal(HtmlTextWriter 编写器)+139 Microsoft.SharePoint.WebPartPages.WebPart.Render(HtmlTextWriter 编写器) +93 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渲染(HtmlTextWriter 编写器)+32 Microsoft.SharePoint.WebPartPages.WebPart.RenderWebPart(HtmlTextWriter 输出)+36 Microsoft.SharePoint.WebPartPages.WebPart.RenderWebPartInternal(HtmlTextWriter 编写器)+139 Microsoft.SharePoint.WebPartPages.WebPart.Render(HtmlTextWriter 编写器) +93 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 部分) +66WebPartPages.WebPart.Render(HtmlTextWriter 编写器)+93 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter 编写器,ControlAdapter 适配器)+27 System.Web.UI.Control.RenderControl(HtmlTextWriter 编写器,ControlAdapter 适配器)+99 System.Web .UI.Control.RenderControl(HtmlTextWriter writer)+25 Microsoft.SharePoint.WebPartPages.SPChrome.RenderPartContents(HtmlTextWriter 输出,WebPart 部分)+66WebPartPages.WebPart.Render(HtmlTextWriter 编写器)+93 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter 编写器,ControlAdapter 适配器)+27 System.Web.UI.Control.RenderControl(HtmlTextWriter 编写器,ControlAdapter 适配器)+99 System.Web .UI.Control.RenderControl(HtmlTextWriter writer)+25 Microsoft.SharePoint.WebPartPages.SPChrome.RenderPartContents(HtmlTextWriter 输出,WebPart 部分)+66