Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have Visual Studio 2008 Professional and I am having issues with expanding and collapsing method code blocks in ASP.Net Generic Handler pages (.ashx)

I would have thought you could do the same thing like in the code behind of .aspx web pages.

I have this same issue on other boxes even with VS 2008 Standard and VS 2005 Professional. All boxes have been fully patched (OS and Visual Studio.)

Does anybody have any suggestions as to enabling this feature?

like image 904
410 Avatar asked Dec 11 '08 14:12

410


4 Answers

You can force Visual Studio to ignore the fact that it's code in front you're working with by going to:

Tools | Options

And opening the "Text Editor | File Extensions" tab.

Create a new entry for extension "ashx", mapped to editor "Microsoft Visual C#" (or "Microsoft Visual Basic", as your preference takes you), and "Add" it.

OK the dialog, close and re-open your ashx file, and your code blocks willl collapse to your hearts content, but the @ directive will be rather ugly.

You have the same issue if you have serverside script in the .aspx file (for example in a web site project and you don't "Place code in a seperate file"), then you cannot collapse the class blocks in there either.

like image 54
Zhaph - Ben Duguid Avatar answered Nov 20 '22 13:11

Zhaph - Ben Duguid


Create a class in the App_Code directory, which the ashx-file just references... like this:

SomethingHandler.ashx:

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

And in the App_Code folder I've created the file SomethingHandler.cs with class SomethingHandler

using System;
using System.Web;
// using blabla...

public class SomethingHandler : IHttpHandler
{
        public void ProcessRequest(HttpContext c)
        {
    etc...

Now I can just open SomethingHandler.cs, edit my C# code with #region collapsing, because the .cs file is opened in the right editor :)

@ WebHandler docs

Tested in VS 2019.

like image 40
bigEsmurf Avatar answered Nov 20 '22 13:11

bigEsmurf


Just select a fragment of code, like:

using System;
using System.Web;
using System.Web.Security;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;

Then Press "Ctrl+M+H" and Vualá... The Outlining Working Now... And Intellisense Too...

To Stop Outlining Press "Ctrl+M+P"...

like image 8
KakashiJack Avatar answered Nov 20 '22 12:11

KakashiJack


Add /// in front of first line.

Like this:

///<%@ WebHandler Language="C#" Class="FooBar"%>
like image 6
Kaspars Avatar answered Nov 20 '22 13:11

Kaspars