7

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

Community
  • 1
  • 1
Barış Velioğlu
  • 5,709
  • 15
  • 59
  • 105

3 Answers3

3

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.

Community
  • 1
  • 1
Vincejtl
  • 169
  • 1
  • 6
2

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.

Community
  • 1
  • 1
brichins
  • 3,825
  • 2
  • 39
  • 60
0

I changed most of my ashx to aspx, just so it can have CodeFile (separate .cs file).

Aximili
  • 28,626
  • 56
  • 157
  • 216