asp.net mvc2中Uploadify中的IO / HTTP错误

发布于 2024-10-21 12:20:26 字数 795 浏览 1 评论 0原文

我正在使用 uploadify 工具上传我的文件而不发回,并且在发布网站后遇到“IO 错误”或“HTTP 错误”问题。

这是我的代码示例:

$('#UploadFile').uploadify({

    'uploader': '/Content/uploadify.swf',

    'script': '/Home/uploadify',

    'cancelImg': '/Content/cancel.png',

    'folder': '/Content/UploadedFiles',

    'auto': true

});

这是我的操作代码

[HttpPost]
public string uploadify()
{
    string fileDirectory = Server.MapPath(@"\Content\UploadedFiles\");
    string signuterName = _fileStore.SaveUploadedFile(Request.Files[0], fileDirectory);
    Session["SignuterfilePath"] = @"/Content/UploadedFiles/" + signuterName;
    return signuterName;
}

http://www.uploadify.com/documentation/

谢谢。

I am using uploadify tool to upload my files with out posting back and I am facing this problem "IO Error" or "HTTP Error" after publishing the site.

This is my code sample :

$('#UploadFile').uploadify({

    'uploader': '/Content/uploadify.swf',

    'script': '/Home/uploadify',

    'cancelImg': '/Content/cancel.png',

    'folder': '/Content/UploadedFiles',

    'auto': true

});

this is my action code

[HttpPost]
public string uploadify()
{
    string fileDirectory = Server.MapPath(@"\Content\UploadedFiles\");
    string signuterName = _fileStore.SaveUploadedFile(Request.Files[0], fileDirectory);
    Session["SignuterfilePath"] = @"/Content/UploadedFiles/" + signuterName;
    return signuterName;
}

http://www.uploadify.com/documentation/

thanks.

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

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

发布评论

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

评论(1

是你 2024-10-28 12:20:26

您似乎有硬编码的网址,在虚拟目录下部署站点时可能会损坏。我建议您在处理 url 时始终使用 URL 帮助程序:

$('#UploadFile').uploadify({
    'uploader': '<%= Url.Content("~/Content/uploadify.swf") %>',
    'script': '<%= Url.Action("Uploadify", "Home") %>',
    'cancelImg': '<%= Url.Content("~/Content/cancel.png") %>',
    'folder': '<%= Url.Content("~/Content/UploadedFiles") %>',
    'auto': true

});

更新:

您的控制器操作通常返回 ActionResults 而不是字符串:

[HttpPost]
public ActionResult Uploadify()
{
    // Notice the argument of the MapPath method:
    string fileDirectory = Server.MapPath(@"~/Content/UploadedFiles/");

    string signuterName = _fileStore.SaveUploadedFile(Request.Files[0], fileDirectory);

    // Warning: You don't have access to the Session in requests
    // performed by Flash plugins
    //Session["SignuterfilePath"] = @"/Content/UploadedFiles/" + signuterName;

    // Return an ActionResult
    return Content(signuterName, "text/plain");
}

您还会注意到我已从控制器操作中删除了 Session 调用。原因是 Uploadify 插件使用 Flash,而 Flash 无法访问 cookie,因此执行请求时不会有任何与其关联的 Session。

You seem to have hardcoded urls which might break when deploying your site under a virtual directory. I would recommend you always using URL helpers when dealing with urls:

$('#UploadFile').uploadify({
    'uploader': '<%= Url.Content("~/Content/uploadify.swf") %>',
    'script': '<%= Url.Action("Uploadify", "Home") %>',
    'cancelImg': '<%= Url.Content("~/Content/cancel.png") %>',
    'folder': '<%= Url.Content("~/Content/UploadedFiles") %>',
    'auto': true

});

UPDATE:

Also your controller actions normally return ActionResults not strings:

[HttpPost]
public ActionResult Uploadify()
{
    // Notice the argument of the MapPath method:
    string fileDirectory = Server.MapPath(@"~/Content/UploadedFiles/");

    string signuterName = _fileStore.SaveUploadedFile(Request.Files[0], fileDirectory);

    // Warning: You don't have access to the Session in requests
    // performed by Flash plugins
    //Session["SignuterfilePath"] = @"/Content/UploadedFiles/" + signuterName;

    // Return an ActionResult
    return Content(signuterName, "text/plain");
}

You will also notice that I have removed the Session call from your controller action. The reason for this is the the Uploadify plugin uses Flash and Flash doesn't have access to cookies, so when the request is performed there won't be any Session associated with it.

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