为什么 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/