Problem with intellisense inline handlers (.ashx) in Visual Studio 2010

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

Similar problems that I found did not help me solve this problem

Visual Studio ASP.Net extends and collapses the problem in shared ashx handlers

I cannot add #region to .ashx in visual studio 2010

+4
source share
3 answers

If the same problem - 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 the file (preferably dedicated) .cs to use as a "code-for", do all the work there (including the implementation of IHttpHandler ) and you have the actual handler in .ashx inherit it without doing anything else:

public class MyHandler: MyIHttpHandlerCodeBehindClass {}

This gives you complete code addition and IntelliSense for your handler class without the problems you mentioned. The only drawback is the extra file, but for me it's worth it.

+2
source

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

+1
source

I come to the same annoyance. To make the @ brichins / link decision a little further, instead of using inheritance in your ashx, just reference the class in the AppCode folder directly.

the ashx file will only contain

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

Then create this file /MyHandler.cs 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 necessary.

+1
source

Source: https://habr.com/ru/post/1389058/


All Articles