2009-02-02 74 views
2

为什么ASP.NET 3.5 Web应用程序中的默认“通用处理程序”代码将属性添加到类中,但没有将正确的名称空间引用添加到属性中。这是他们给你出的现成的模板:ASP.NET 3.5中的处理程序(ASHX)发生了什么

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; 

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

回答

4

编辑:现在我明白了,当你添加一个通用处理器到Web应用程序(对不起,我错过了你的问题第一次)我得到新的无功能的模板。我同意其他用户应该编辑默认模板。如果你使用MVC,你不需要处理程序了。

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

如果你要编辑的模板,它位于:C:\ Program Files文件\微软的Visual Studio 9.0 \ Common7 \ IDE \的ItemTemplate \ CSHARP \网络\ 1033 \ Handler.zip

+0

我动过到MVC。但是我仍然需要在一些升级到3.5的旧应用程序中使用ASHX文件。我只是修复我的模板。感谢您的所有帮助+1并回答。 – BuddyJoe 2009-02-03 20:09:18