How to dynamically compile an ashx file?

I have an ashx file in an asp.net web project. It has code behind the cs file. The cs file is compiled into the project dll and deployed to production. I have not found a way to dynamically modify the cs file without deploying the entire project DLL.

I add C # code to aspx file (not.cs) after deployment, I can make changes to one aspx file and deploy, IIS can dynamically compile and merge my code behind C # code.

Is it possible to do a similar thing with the ashx file?

Here is a quote from MSDN. http://msdn.microsoft.com/en-us/library/ms366723(v=vs.100).aspx

ASP.NET supports dynamic compilation of ASP.NET pages (.aspx files), ASP.NET Web Services (.asmx files), ASP.NET HTTP handlers (.ashx files)

thanks, it could save a lot of time!

+3


source to share


1 answer


I understood that.

  • add a common handler - Handler1.ashx in visual studio
  • delete the cs file that was automatically generated.
  • 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;
        }
    }
}

      

+4


source







All Articles