ashx 通用处理程序中的 Visual Studio ASP.Net 展开和折叠问题

发布于 2024-07-09 23:17:54 字数 262 浏览 14 评论 0原文

我有 Visual Studio 2008 Professional,并且在 ASP.Net 通用处理程序页面 (.ashx) 中展开和折叠方法代码块时遇到问题,

我本以为您可以像在 .aspx 网页后面的代码中那样执行相同的操作。

即使使用 VS 2008 Standard 和 VS 2005 Professional,我在其他机器上也遇到同样的问题。 所有盒子都已完全修补(操作系统和 Visual Studio)。

有人对启用此功能有任何建议吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

眼眸里的那抹悲凉 2024-07-16 23:17:54

您可以强制 Visual Studio 忽略它是您正在使用的代码这一事实,方法是转到:

工具 | 选项

并打开“文本编辑器|文件扩展名”选项卡。

为扩展“ashx”创建一个新条目,映射到编辑器“Microsoft Visual C#”(或“Microsoft Visual Basic”,根据您的喜好而定),然后“添加”它。

确定对话框,关闭并重新打开您的 ashx 文件,您的代码块将崩溃到您心中的内容,但 @ 指令将相当难看。

如果 .aspx 文件中有服务器端脚本(例如在网站项目中并且您没有“将代码放在单独的文件中”),那么您也会遇到同样的问题,那么您也无法折叠其中的类块。

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.

心的位置 2024-07-16 23:17:54

App_Code 目录中创建一个类,ashx 文件只是引用该类...如下所示:

SomethingHandler.ashx:

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

App_Code 文件夹中我创建了该文件SomethingHandler.cs 和类 SomethingHandler

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

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

现在我可以打开 SomethingHandler.cs,使用 #region 折叠编辑我的 C# 代码,因为 .cs 文件是在正确的编辑器中打开的: )

@ WebHandler 文档< /a>

在 VS 2019 中测试。

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.

指尖上的星空 2024-07-16 23:17:54

只需选择一段代码,例如:

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

然后按“Ctrl+M+H”,然后 Vualá...大纲现在正在工作...还有 Intellisense...

要停止大纲,请按“ >Ctrl+M+P“...

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"...

何时共饮酒 2024-07-16 23:17:54

在第一行前面添加///。

像这样:

///<%@ WebHandler Language="C#" Class="FooBar"%>

Add /// in front of first line.

Like this:

///<%@ WebHandler Language="C#" Class="FooBar"%>
多彩岁月 2024-07-16 23:17:54

不会干扰 IntelliSense 或要求您编辑第一行的最简单的修复方法是禁用“智能”缩进并将其设置为“阻止”:

工具 -> Visual Studio 中的选项

The easiest fix that won't interfere with IntelliSense or require you to edit the first line is to disable 'smart' indenting and set it to 'block' instead:

Tools -> Options in Visual Studio

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文