Why I cannot use HttpResponseMessage class?

a 夏天 提交于 2020-01-07 03:26:07

问题


I'm new to ASP.NET Web API and want to make HttpResponseMessage instance from a utility class I made. Then I made very simple class.

But following compile error occurred.

CS0246: The type or namespace name 'HttpResponseMessage' could not be found (are you missing a using directive or an assembly reference?)

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 is available from Controller Class which was made automatically by ASP.NET but not my Utility class.

What am I missing?


回答1:


I have noticed that you placed your class in App_Code folder in your project. This folder has a special purpose in ASP.NET world and should be used for shared classes and business objects that you want to compile as part of your application. So either move your class into another folder, or change its Build Action in properties section to Compile.



来源:https://stackoverflow.com/questions/41757799/why-i-cannot-use-httpresponsemessage-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!