使用HttpWebRequest,将文件上传到SharePoint时,WebResponse是未编译的aspx页面

发布于 2024-12-27 09:37:12 字数 3210 浏览 2 评论 0原文

这是一个奇怪的现象。多年来,一些用于将文件上传到 SharePoint 的代码一直在我的开发计算机上运行。前几天它刚刚停止工作!没有抛出异常,但 WebResponse 中返回了一个奇怪的响应字符串。这是代码:

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(absoluteUrl);

            if (this._authenticationService == null)
            {
                // Windows authentication
                request.Credentials = _credentials;
            }
            else
            {
                // Forms authentication
                request.CookieContainer = this._authenticationService.CookieContainer;
            }

            request.Method = "PUT";
            byte[] buffer = new byte[4 * 1024];
            using (Stream stream = request.GetRequestStream())
            {
                using (FileStream fs = File.OpenRead(localFilePath))
                {
                    for (int i = fs.Read(buffer, 0, buffer.Length); i > 0; i = fs.Read(buffer, 0, buffer.Length))
                    {
                        stream.Write(buffer, 0, i);
                    }
                }
            }
            WebResponse response = request.GetResponse();
            response.Close();

如果我添加一些代码来检查实际响应,如下所示:

StreamReader responseReader = new StreamReader(response.GetResponseStream());

responseReader.ReadToEnd();

该代码的输出是这样的,一个看似未编译的 aspx 页面!!!!:

<%@ Assembly Name=\"Microsoft.SharePoint.ApplicationPages, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\"%> ; <%@ 页面语言=\"C#\" 继承=\"Microsoft.SharePoint.ApplicationPages.ErrorPage\" MasterPageFile=\"~/_layouts/simple.master\" %> <%@ 导入命名空间=\"Microsoft.SharePoint.ApplicationPages\" %> <%@ 注册标记前缀=\"SharePoint\" 命名空间=\"Microsoft.SharePoint.WebControls\" 程序集=\"Microsoft.SharePoint,版本=12.0.0.0,文化=中性,PublicKeyToken=71e9bce111e9429c\" %> <%@ Register Tagprefix=\"Utilities\" 命名空间=\"Microsoft.SharePoint.Utilities\" Assembly=\"Microsoft.SharePoint,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c\" %> <%@ 导入命名空间=\"Microsoft.SharePoint\" %>\r\n<%@ 注册标记前缀=\"SharePoint\" 命名空间=\"Microsoft.SharePoint.WebControls\" 程序集=\"Microsoft.SharePoint ,版本=12.0.0.0,文化=中性,PublicKeyToken=71e9bce111e9429c\" %> <%@ 注册标记前缀=\"实用程序\"命名空间=\"Microsoft.SharePoint.U tilities\" Assembly=\"Microsoft.SharePoint,版本=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c\" %> <%@ 导入命名空间=\"Microsoft.SharePoint\" %>\r\n \r\n\t\" EncodeMethod='HtmlEncode'/>\r\n\r\n\r\n\t\" EncodeMethod='HtmlEncode'/>\r\n\r\n\r\n\t\r\n \t\r\n\r\n\r\n \r\n\t\r\n\t\r\n\t \r\n\t\t \r\n\t \r\n \t

\r\n\t\t<%\r\n\t\t\tif (是管理站点)\r\n\t\t\t{ %>\r\n\t\t\t\t\ " EncodeMethod=\"NoEncode\" runat=\"server\"> \" EncodeMethod='HtmlEncode'/> \r\n\t\t<% } else { %>\r\n\t\t\t\t\" EncodeMethod=\"NoEncode\" runat=\ “服务器\”

\" EncodeMethod='HtmlEncode'/> \r\n\t\t<% } %>\r\n\t\t\r\n\t\r\n\t\r\ n \r\n\r\n\t var gearPage = document.getElementById('GearPage');\r\n\t if(null != gearPage)\r\n\t {\r\n\t\t gearPage.parentNode.removeChild(gearPage);\r\n\t\t document.title = \"' EncodeMethod='HtmlEncode'/>\";\r\n\t }\r\n\r\n

发生了什么事?!?!

This is a weird one. For years, a bit of code to upload files to SharePoint has been working on my dev machine. It just stopped working the other day! No exceptions are being thrown, but there is a weird response string coming back in the WebResponse. Here's the code:

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(absoluteUrl);

            if (this._authenticationService == null)
            {
                // Windows authentication
                request.Credentials = _credentials;
            }
            else
            {
                // Forms authentication
                request.CookieContainer = this._authenticationService.CookieContainer;
            }

            request.Method = "PUT";
            byte[] buffer = new byte[4 * 1024];
            using (Stream stream = request.GetRequestStream())
            {
                using (FileStream fs = File.OpenRead(localFilePath))
                {
                    for (int i = fs.Read(buffer, 0, buffer.Length); i > 0; i = fs.Read(buffer, 0, buffer.Length))
                    {
                        stream.Write(buffer, 0, i);
                    }
                }
            }
            WebResponse response = request.GetResponse();
            response.Close();

If I add some code to check the actual response like this:

StreamReader responseReader = new StreamReader(response.GetResponseStream());

responseReader.ReadToEnd();

The output from that code is this, a seemingly uncompiled aspx page!!!!:

<%@ Assembly Name=\"Microsoft.SharePoint.ApplicationPages, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\"%> <%@ Page Language=\"C#\" Inherits=\"Microsoft.SharePoint.ApplicationPages.ErrorPage\" MasterPageFile=\"~/_layouts/simple.master\" %> <%@ Import Namespace=\"Microsoft.SharePoint.ApplicationPages\" %> <%@ Register Tagprefix=\"SharePoint\" Namespace=\"Microsoft.SharePoint.WebControls\" Assembly=\"Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\" %> <%@ Register Tagprefix=\"Utilities\" Namespace=\"Microsoft.SharePoint.Utilities\" Assembly=\"Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\" %> <%@ Import Namespace=\"Microsoft.SharePoint\" %>\r\n<%@ Register Tagprefix=\"SharePoint\" Namespace=\"Microsoft.SharePoint.WebControls\" Assembly=\"Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\" %> <%@ Register Tagprefix=\"Utilities\" Namespace=\"Microsoft.SharePoint.U
tilities\" Assembly=\"Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\" %> <%@ Import Namespace=\"Microsoft.SharePoint\" %>\r\n\r\n\t\" EncodeMethod='HtmlEncode'/>\r\n\r\n\r\n\t\" EncodeMethod='HtmlEncode'/>\r\n\r\n\r\n\t\r\n\t\r\n\r\n\r\n \r\n\t\r\n\t\r\n\t \r\n\t\t \r\n\t \r\n\t

\r\n\t\t<%\r\n\t\t\tif (IsAdministrationSite)\r\n\t\t\t{ %>\r\n\t\t\t\t\" EncodeMethod=\"NoEncode\" runat=\"server\"> \" EncodeMethod='HtmlEncode'/> \r\n\t\t<% } else { %>\r\n\t\t\t\t\" EncodeMethod=\"NoEncode\" runat=\"server\"

\" EncodeMethod='HtmlEncode'/> \r\n\t\t<% } %>\r\n\t\t\r\n\t\r\n\t\r\n \r\n\r\n\t var gearPage = document.getElementById('GearPage');\r\n\t if(null != gearPage)\r\n\t {\r\n\t\t gearPage.parentNode.removeChild(gearPage);\r\n\t\t document.title = \"' EncodeMethod='HtmlEncode'/>\";\r\n\t }\r\n\r\n

What's happened?!?!

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

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

发布评论

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

评论(1

累赘 2025-01-03 09:37:12

好的,我卸载并重新安装了带有 SP2 的 WSS 和最新的累积更新包,并重新连接到现有场,这解决了这个问题!

Ok, I caved and uninstalled and reinstalled WSS with SP2, and the latest cumulative update package, and reconnected to the existing farm and that's sorted this problem!

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