问题
I have a ashx file in a asp.net web project. It has a code behind cs file. The cs file is compiled into project dll & deployed to production. I found no way to dynamically change the cs file without deploying the whole project dll.
I have been putting c# code into aspx (not .cs) file, after deployment, I can make change to a single aspx file, and deploy, IIS can dynamically compile & merge with its code behind c# code.
Can I do the similar thing with ashx file?
Here is a quote from MSDN. http://msdn.microsoft.com/en-us/library/ms366723(v=vs.100).aspx
ASP.NET supports the dynamic compilation of ASP.NET pages (.aspx files), ASP.NET Web services (.asmx files), ASP.NET HTTP handlers (.ashx files)
thanks, this can save me lots of time!
回答1:
I figured it out.
- add a Generic handler - Handler1.ashx in visual studio
- delete the cs file which auto-created.
- open ashx again,
- remove CodeBehind="Handler1.ashx.cs"
- add c# code below
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
public class Handler1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World2");
}
public bool IsReusable
{
get
{
return false;
}
}
}
来源:https://stackoverflow.com/questions/25510189/how-to-dynamically-compile-a-ashx-file