0

我是 ASP.NET Web API 的新手,想HttpResponseMessage从我制作的实用程序类中创建实例。然后我做了很简单的课。

但是发生了以下编译错误。

CS0246:找不到类型或命名空间名称“HttpResponseMessage”(您是否缺少 using 指令或程序集引用?)

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

namespace myapplication.App_Code.Utils
{
    public class HttpUtility
    {
        // compile error here
        public HttpResponseMessage GetHttpResponseMessage ()
        {
            return new HttpResponseMessage();
        }
    }
}

HttpResponseMessage可从由 ASP.NET 自动生成的控制器类获得,但不是我的实用程序类。

我错过了什么?

4

1 回答 1

1

我注意到您将课程放在App_Code项目的文件夹中。此文件夹在 ASP.NET 世界中具有特殊用途,应该用于您想要编译为应用程序一部分的共享类和业务对象。因此,要么将您的类移动到另一个文件夹中,要么将其Build Action在属性部分更改为Compile.

于 2017-01-20T10:36:08.853 回答