Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generic Handlers (.ashx) intellisense issue on Visual Studio 2010 [duplicate]

I am trying to expand and collapse methods and other things on an ashx file like any other code behind file. When I do tools > options > text editor and adding ashx as an extention of visual studio c#, everything seems ok at the beginning. I can expand and collapse the methods also see the properties and methods at the top of the file. But then I lost most of intellisense. I cant reach my userdefined objects and methods.

Similar Issues that I have found did not help me to solve this problem

Visual Studio ASP.Net expand and collapse issue in ashx generic handlers

i can't add #region to .ashx in visual studio 2010

like image 357
Barış Velioğlu Avatar asked Jan 03 '12 11:01

Barış Velioğlu


2 Answers

Ran in to this same annoyance. To take @brichins solution/reference a little further, instead of using inheritance in your ashx just reference the class in the AppCode folder directly.

the ashx file would only contain the following

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

Then create that class/MyHandler.cs file in the AppCode folder

using System;
using System.Web;

public class MyHandler : IHttpHandler {

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

    public bool IsReusable {
        get {
            return false;
        }
    }

}

Use namespaces to avoid class name conflicts if needed.

like image 85
Vincejtl Avatar answered Nov 11 '22 01:11

Vincejtl


Had the same issue - this answer (to the first question you mentioned, but posted after you asked) seems to be the best option for me.

To summarize: create a separate class in a (preferably dedicated) .cs file to use as "code-behind", do all the work there (including implementing IHttpHandler) and have your actual handler in the .ashx just inherit it without doing anything else:

public class MyHandler : MyIHttpHandlerCodeBehindClass{}

This gives you full code-folding and IntelliSense for your handler class without the issues you mentioned. Only downside is an additional file, but to me it's worth it.

like image 20
brichins Avatar answered Nov 11 '22 01:11

brichins