Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to add .ashx file in Visual Studio

I recently downloaded Visual Studio 2012 for web(express edition) and I am creating a simple asp .net empty web site. I am retreiving the data from mysql database by using Websockets. For that i want to add .ashx file to my solution but when i am hitting add new item it is not giving me the option to add .ashx file(handler file).

edited-- all the option i am getting for adding a new file are Text File html page style sheet xml file xml schema xslt file sql file

like image 556
arjun Avatar asked Aug 26 '13 16:08

arjun


2 Answers

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
like image 138
sealz Avatar answered Sep 28 '22 04:09

sealz


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

like image 23
Anton Avatar answered Sep 28 '22 05:09

Anton