使用HttpWebRequest,将文件上传到SharePoint时,WebResponse是未编译的aspx页面
这是一个奇怪的现象。多年来,一些用于将文件上传到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我卸载并重新安装了带有 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!