.net - ASP.NET 3.5 中的处理程序 (ASHX) 发生了什么

标签 .net asp.net handler ashx

为什么 ASP.NET 3.5 Web 应用程序中的默认“通用处理程序”代码向类添加属性,而不是正确的命名空间引用。这是他们为您提供的开箱即用的模板:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Handler1
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class People : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write("Hello World");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

为什么顶部没有一行:

using System.Web.Services;

这是 Microsoft 默认模板中的错误吗?我错过了什么吗?

最佳答案

编辑:我现在看到了,当您将通用处理程序添加到网络应用程序时(抱歉我第一次在您的问题中错过了这一点)我得到了新的非功能模板。我同意其他用户的观点,您应该只编辑默认模板。但是,如果您使用 MVC,则不再需要处理程序。

看起来这是一个已知的错误,here's the MS Connect issue for it .

如果要编辑模板,它位于此处:C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Web\1033\Handler.zip

关于.net - ASP.NET 3.5 中的处理程序 (ASHX) 发生了什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/505381/

相关文章:

c# - 如何在 ASP.Net 中转储响应 header

.net - LINQ-在可为空的列上连接表

android - 在多个 Activity 中使用处理程序

http-status-code-404 - django教程: custom 404 and 500 views

java - 内存不足错误: Could not allocate JNI Env

.net - 使用 .NET(C#) 为 Adob​​e(Reader 和 PhotoShop)编写插件

c# - 如何在构建时将其他文件包含到 C# 的输出目录中?

asp.net - Windows 8 RTM 上的 Visual Studio 2012 Web 发布无法启动浏览器

c# - 组合 DataTextField 中的两个字段。这可能吗?

c# - 将文件从 Angular 发送到 .NET Core