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

发布于 2024-07-13 00:46:39 字数 922 浏览 13 评论 0原文

为什么 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 默认模板中的错误吗? 我错过了什么吗?

Why does the default "generic handler" code in an ASP.NET 3.5 web application add attributes to the class but not the correct namespace references. This is the template they give you out-of-the-box:

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;
            }
        }
    }
}

Why don't they have a line at the top:

using System.Web.Services;

Is this a bug in Microsoft's default template? Am I missing something?

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

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

发布评论

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

评论(1

遗忘曾经 2024-07-20 00:46:39

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

看起来这是一个已知错误,这是 MS Connect 问题

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

EDIT: I see it now, when you add a Generic Handler to a web application (sorry I missed that in your question the first time) I get the new non-functioning template. I agree with the other user that you should just edit the default template. If you're using MVC, you don't need handlers anymore however.

Looks like it's a known bug, here's the MS Connect issue for it.

If you want to edit the template, it's located here: C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Web\1033\Handler.zip

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