我有简单的开箱即用的处理器如何通过网址或其他方式从WebApi项目调用Handler.ashx?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace XXX.XXX.WebApi.Controllers
{
/// <summary>
/// Summary description for Handler1
/// </summary>
public class Handler1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
我的文件结构
如何通过URL调用这个Hello World示例?我经历了很多教程去了,总有一些事情是错误的......像App_Code文件夹等
有什么我想(或用)
https://msdn.microsoft.com/en-us/library/ms228090.aspx
https://www.codeproject.com/articles/538589/theplustruthplusaboutplushttphandlersplusandpluswe
和许多其他的事情,而不成功在我的情况。有任何想法吗?
你给web api项目添加处理程序的原因是什么? – Darren
我读过ashx很适合处理文件,并且有人说ashx最适合那种文件。 –
问题是你在混合技术。真的,这听起来像你想知道如何接受一个Web API中的文件 - 这是更好的问题,然后 - 像这样http://stackoverflow.com/questions/34168395/how-to-post-and-receive- a-file-with-web-api - 处理程序以不同的方式做到这一点(更简单但不一定更好) - 我将在控制器中使用,而不是在web api项目中使用处理程序 – Darren