2

i create a generic handler (ashx) but i am trying to add region in my code like the following

 #region MyRegionName
   context.Response.ContentType = "text/plain";
   context.Response.Write("Hello World");
 #endregion

there is no error but the problem that there is no expand and collapse.

please any advice ? note: i am using visual studio 2010

Hiyasat
  • 8,601
  • 7
  • 33
  • 59

4 Answers4

7

hi i think i figure out the answer my self

in visual studio go to:

1- Tools -> option -> select Text Editor.
2- in the right pane add an extension "ashx" and choose from the drop down list which editor u use .. i select microsoft visual c#.
3- in the bottom check on "map extensionless to : the same selection above.
4- click ok and close the ashx page and reopen it.

thx every body for the answers

Hiyasat
  • 8,601
  • 7
  • 33
  • 59
  • 2
    This isn't really a fix, it is a hack. All you are doing here is switching the default editor for ashx to the C# editor. You may get the regions working, but the editor will now start complaining about other aspects of the file that it doesn't see as valid C#. You are now basically using the wrong editor for the job. – Rob Levine Mar 15 '11 at 11:29
  • 1
    Wow ! ... check out what breaks after this fix – V4Vendetta Mar 15 '11 at 11:43
  • it doesn't break that much it just break the ashx direct <%@ WebHandler Language="C#" ... – Hiyasat Mar 17 '11 at 10:54
  • This isn't usable? No intellisense because the first line is incorrect? – Ian Grainger May 16 '13 at 11:08
2

This is by design, see the explanation here: http://forums.asp.net/t/1162769.aspx#1928580. The problem is, that the ashx file is not handled by the C# editor but by the ASP.NET editor.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
1

EDIT: Hang on a minute - I've just re-read your question. An .ashx file, like an .asmx or .aspx file is a markup file, not a code file. You can't use regions in these files. You can use regions in the code behind files associated with them (e.g. the .ashx.cs files) only.

Original Answer: Generally, whenever I get these sort of unexplained odd behaviours in VS2010, I reset all the settings, which normally resolves the issue.

Try Tools->Import and Export Settings->Reset All Settings and see if that fixes your region issue.

If not, it may be related to a bad add-in or extension. Try disabling extensions/add-ins to see if that fixes your problem, alternatively try starting up in safe mode and see if the IDE behaves:

DEVENV.EXE /safemode

Hope this helps.

Rob Levine
  • 40,328
  • 13
  • 85
  • 111
-3
#region yourRegionName
//your code
#endregion
Pabuc
  • 5,528
  • 7
  • 37
  • 52