ASP.NET 3.5 中的处理程序 (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 默认模板中的错误吗? 我错过了什么吗?
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:我现在看到了,当您将通用处理程序添加到网络应用程序时(抱歉我第一次在您的问题中错过了这一点),我得到了新的无法运行的模板。 我同意其他用户的观点,您应该只编辑默认模板。 如果您使用 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