我在这方面已经太久了,我敢肯定有人会在几秒钟内指出我的错误。
我的公司有一个 ipad 应用程序,可以为我们的销售人员下载销售材料(PowerPoint、视频等)。所有资源都位于 SharePoint 内的文档库中。我没有将文档库公开(并且不太安全),而是创建了一个 .aspx 页面,其中包含一个用于获取文档的 Web 部件。ipad 应用程序联系 .aspx 页面并发送两个查询:“token”和“document”。令牌本质上是一个密码,因此 Web 部件知道它来自 ipad 应用程序。如果令牌正确,则 Web 部件将获取指定的任何文档。
这是我的问题。该文档按原样获取并交付,但是如果我尝试下载另一个文档,或为此导航服务器上的任何其他位置,我会收到服务器错误。我必须关闭浏览器(也就是结束会话)。
我得到的错误在这里解释:http : //blog.tylerholmes.com/2008/07/problem-with-sharepoint.html
但是,我不想在该博客上使用修复程序,因为我知道我的代码导致了问题,并且我想修复问题的根源。
我的 Web 部件代码如下:
protected override void CreateChildControls()
{
string toRender = string.Empty;
SPWeb webInUserContext = SPContext.Current.Web;
SPSite SiteInUserContext = SPContext.Current.Site;
Guid webGuid = webInUserContext.ID;
Guid siteGuid = SiteInUserContext.ID;
//gives visitors the authority to see the dam data
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(siteGuid))
{
using (SPWeb web = site.OpenWeb(webGuid))
{
using (DAM dam = new DAM())
{
String mystring = HttpContext.Current.Request.Url.AbsoluteUri;
//If the request contains the correct token
if (mystring.ToString().Contains("REgrgg0434GgdLk6"))
{
//Get the document data into a byte array
byte[] buf = new byte[0];
using (var wc = new System.Net.WebClient())
{
//Right now I'm just hard-coding a document url for testing, rather than
//getting it from the url query
String url = "http://web-dev/sites/damedit/DocLibrary/document.ppt";
System.Net.CredentialCache cc = new System.Net.CredentialCache();
cc.Add(new Uri(url), "NTLM", new System.Net.NetworkCredential("username", "password", "domain"));
wc.Credentials = cc;
buf = wc.DownloadData(url);
}
//Rewrite the current response so that it contains the document
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=\"document.ppt\"");
HttpContext.Current.Response.BinaryWrite(buf);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
}
}
}
});
base.CreateChildControls();
}
任何帮助将非常感激!