启动C#Web API时出现错误CS0246

时间:2015-04-29 10:10:54

标签: c# asp.net-web-api2

我正在开发一个WEB API 2项目,我正在尝试在我的REST服务器上设置一个基本的身份验证系统。 我在启动应用程序时遇到错误问题而我找不到此错误的来源。

课程代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;

namespace CalypsoWebApplication.App_Code
{
    public class ResultWithChallenge : IHttpActionResult
    {
        private readonly System.Web.Http.IHttpActionResult next;

        public ResultWithChallenge(IHttpActionResult next)
        {
            this.next = next;
        }

        public async Task<HttpResponseMessage> ExecuteAsync(
                                    CancellationToken cancellationToken)
        {
            var res = await next.ExecuteAsync(cancellationToken);
            if (res.StatusCode == HttpStatusCode.Unauthorized)
            {
                res.Headers.WwwAuthenticate.Add(
                   new AuthenticationHeaderValue("Basic", null));
            }

            return res;
        }
    }
}

Erreur au lancement:

Message d'erreur du compilateur:CS0246:Le type ou le nom d'espace de noms'HttpResponseMessage'est introuvable(使用ouuneréférenced'assestest-elle manquante进行指令?)

英文翻译:无法找到类型或命名空间'HttpResponseMessage',是使用指令还是汇编引用缺失?

Erreur来源: Ligne 22:} Ligne 23: Ligne 24:公共异步任务ExecuteAsync( Ligne 25:取消语音取消语言) Ligne 26:{ Fichier来源:e:\ Users \ mehin \ Documents \ Visual Studio 2013 \ Projects \ Calypso \ CalypsoWebApplication \ App_Code \ ResultWithChallenge.cs Ligne:24

https://msdn.microsoft.com/fr-fr/library/w7xf6dxs.aspx查看此错误的可能来源时,我仍然不明白为什么会发生这种情况。

  • Target Framework .NET 4.5
  • 在我的项目参考中,我有“System.Net.Http”,其目标是System.NetNHttp.dll,版本4.0.0.0
  • 尝试使用System.Net.http对HttpResponseMessage作为前缀时,仍会出现错误。
  • 在Visual Studio 2013中清理和构建我的解决方案时,我没有收到任何错误。我只在启动应用程序时才能得到它。

我不知道还能添加什么,请不要犹豫,询问更多细节。

0 个答案:

没有答案