【发布时间】:2010-11-22 14:44:25
【问题描述】:
我有一个由 JQuery 在共享点页面上生成的 html。我想在这个 html 中使用 uploadify 将文件上传到服务器。 Alexander 提供了以下部分基于 http://www.uploadify.com/forum/viewtopic.php?f=5&t=45 的示例代码。
上传.ashx
<%@ Assembly Name="ClassName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f099e668beaaa0f9" %>
<%@ WebHandler Language="C#" CodeBehind="Upload.ashx.cs" Class="Site.RootFiles.TEMPLATE.LAYOUTS.other.Upload" %>
上传.ashx.cs
public class Upload : IHttpHandler
{
public void ProcessRequest(HttpContext context) {
HttpPostedFile oFile = context.Request.Files["Filedata"];
if (oFile != null) {
const string sDirectory = "c:\\";
if (!Directory.Exists(sDirectory))
Directory.CreateDirectory(sDirectory);
oFile.SaveAs(Path.Combine(sDirectory, oFile.FileName));
context.Response.Write("1");
}
else {
context.Response.Write("0");
}
}
public bool IsReusable {
get {
return false;
}
}
}
文件没有上传到服务器。唯一抛出的事件是 onProgress 事件。导航到 _layouts/other/Upload.ashx 返回 0(这是正确的),因此文件在那里。
主要问题是如何让这个与分享点一起玩?我尝试远程调试upload.ashx文件,但它不允许我在VS中添加断点,所以远程调试什么都不做。
更新 1
这个问题Visual Studio ASHX files debugging 得到了调试工作。
当我直接导航到页面时,0 被写入页面。调试器触发,一切都很好。当脚本运行时,它没有命中 Upload.ashx,因为没有命中断点。我想我对 Upload.ashx 的引用不正确。我尝试在 js 中使用http://mysite/_layouts/other/Upload.ashx 仍然没有乐趣...
更新 2
经过一些测试,问题似乎是它要求我再次登录 Share Point(我已登录)。这导致它绊倒。任何想法如何确保我的身份验证被提取?
更新 3
这真的很奇怪。我很想说这是我的 IE8 中的一个设置,因为它适用于队友。
当我直接浏览到 /_layouts/other/Upload.ashx 时,我从未被要求进行身份验证。 当我通过 JS 访问时,即使我以前登录过,有时也会被要求进行身份验证。
【问题讨论】:
标签: c# .net sharepoint wss uploadify