首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到Backload FileHandler

找不到Backload FileHandler
EN

Stack Overflow用户
提问于 2015-10-12 17:44:06
回答 2查看 513关注 0票数 1

我正尝试在ASP.NET网站中使用带Backload的jQuery文件上传作为处理程序,但无法正常工作。

这是Default.aspx:

代码语言:javascript
复制
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE HTML>
<html>
<head runat="server">
<meta charset="utf-8">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="js/vendor/jquery.ui.widget.js"></script>
<script src="js/jquery.iframe-transport.js"></script>
<script src="js/jquery.fileupload.js"></script>
<script src="js/uploader.js"></script>
</head>
<body>
<input id="fileupload" type="file">
</body> 
</html>

以及用于启用文件上传插件的js:

代码语言:javascript
复制
$(document).ready(function () {
    var handlerUrl = "/Backload/FileHandler";

    $('#fileupload').fileupload({
        url: handlerUrl
    });
});

我已经使用NuGet安装了Backload,并将jQuery文件上传加载到我的项目中。所有引用都加载正常(控制台中没有错误)。当我尝试上传一个文件时,我得到了一个错误:Failed to load resource: the server responded with a status of 404 (Not Found),并且所记录的资源是http://localhost:61076/Backload/FileHandler

这里我漏掉了什么?

注意:这些代码我都没有写过。这些都是来自相关来源的复制/粘贴示例,因为我正在尝试在实际建立自己的网站之前获得一个基本的工作。

EN

回答 2

Stack Overflow用户

发布于 2015-10-14 00:10:49

刚刚看到您有一个ASP.NET WebForms项目。Backload默认使用MVC。在传统的WebForms项目中,有两种方法可以让Backload运行:

添加和注册(Web.Config)

  • NuGet包到项目中并添加路由。您可以在此处删除"~/Backload/ controller“中的控制器,以避免依赖MVC。

最简单的方法是添加MVC NuGet包,并在~/App_Start/RouteConfig.cs中配置路由:

代码语言:javascript
复制
    public static void RegisterRoutes(RouteCollection routes)
    {
        var settings = new FriendlyUrlSettings();
        settings.AutoRedirectMode = RedirectMode.Permanent;
        routes.EnableFriendlyUrls(settings);

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }

第二个解决方案(添加HttpHandler)如下所示:https://github.com/blackcity/Backload/tree/master/Examples/Backload.Standard.2.0.Full/Backload.Demo/Other/Handler

示例:

代码语言:javascript
复制
public class FileHandler : HttpTaskAsyncHandler
{
    /// <summary>
    /// File handler demo for classic Asp.Net or HTML. 
    /// To access it in an Javascript ajax request use: <code>var url = "/Handler/FileHandler.ashx";</code>.
    /// </summary>
    /// <remarks>
    /// NOTE. Edit the web.config file to allow the DELETE method in the system.webServer.handlers section
    /// </remarks>
    public override async Task ProcessRequestAsync(HttpContext context)
    {
        try
        {
            // Wrap the request into a HttpRequestBase type
            HttpRequestBase request = new HttpRequestWrapper(context.Request);


            // Create and initialize the handler
            IFileHandler handler = Backload.FileHandler.Create();
            handler.Init(request);


            // Call the execution pipeline and get the result
            IBackloadResult result = await handler.Execute();


            // Write result to the response and flush
            ResultCreator.Write(context.Response, result);
            context.Response.Flush();

        }
        catch
        {
            context.Response.StatusCode = 500;
        }

    }
}
票数 2
EN

Stack Overflow用户

发布于 2015-10-12 17:53:30

我认为您在FileHandler操作名称http://localhost:61076/Backload/FileHandler中遗漏了“r

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33077989

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档