我创建了一个自定义HTTPHandler来处理客户端使用jQuery文件上传的数据。
当我的应用在Windows 10 Home上运行时,无法加载我的自定义HTTPHandler。
我的自定义HTTP处理程序代码如下:
public class FileUploadHandler : IHttpHandler
{
private string fSource = "";
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//context.Response.ContentType = "application/json";
var sheetName = "<select style='width:100%' id='ddlSheetName'></select>";
var isUploaded = false;
try
{
if (context.Request.Files.Count > 0)
{
var files = context.Request.Files;
var file = files[0];
var fileName = "";
//index = fileName.LastIndexOf('\\');
//fileName = fileName.Substring(index+1, fileName.Length - index-1);
var now = DateTime.Now;
fileName = now.Year + "_" + now.Month + "_" + now.Day + "_" + now.Hour + "_" + now.Minute + "_" + now.Second + ".xlsx";
var fname = context.Server.MapPath("~/FileUpload/" + fileName);
file.SaveAs(fname);
sheetName = GetSheetName(fileName);
isUploaded = true;
}
}
catch (HttpException e)
{
throw e;
}
context.Response.Write(JsonConvert.SerializeObject(new { isUploaded = isUploaded, message = sheetName }));
}
这是正在使用的web.config
<configuration>
...
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<handlers>
<add name="FileUploadHandler" path="*.ashx" verb="*" type="NorthStar.FundManagerWeb._Transaction.FileUploadHandler"/>
</handlers>
</system.webServer>
.....
</configuration>
我在问题中尝试了解决方案:
但我无法解决这个问题。