Not able to add .ashx file in Visual Studio

Try to add "Web">"C#">"Generic Handler" file


In Visual Studio 2015:

  • Right click on the project
  • Select Add... New Item
  • You will find it under under Visual C#, Web tree on the left.
  • Select Generic Handler on the right
  • Give it a name, such as Handler1.ashx.

The item is listed as "Generic Handler"

It is also just a file type and if you can't add it you can just add an html page. When adding call it something like Handler.ashx.

Then copy and paste the default handler code, and rebuild.

<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;

public class Handler : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        context.Response.Write("Hello World");
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}

Visual Sudio will stop yelling at you and underlining things once you rebuild and close/reopen the new .ashx file.

If it still has issues something is wacked up somewhere. If you have older versions of studio see if it will let you create a .ashx there. Then maybe import it?

EDIT-Visual Studio Command Prompt for Missing Templates

You can run Visual Studio Command promt and look into `devenv' if you are missing templates but have them in the templates directories. They may just need to be installed.

devenv /installvstemplates