1

我有一个 Windsor ASP.NET MVC WebAPI 项目设置,例如:

http://nikosbaxevanis.com/2012/07/16/using-the-web-api-dependency-resolver-with-castle-windsor-scoped-lifetime/

当我的控制器返回 OK 状态时,一切正常。但是,如果我尝试发送错误状态,例如 not NotFound,则会收到以下错误:

Castle.MicroKernel.Lifestyle.Scoped.CallContextLifetimeScope+SerializationReference,Castle.Windsor,版本=3.1.0.0,文化=中性,PublicKeyToken=407dd0808d44fbdc

这是我的控制器方法:

    // GET api/values
    public IEnumerable<string> Get()
    {
        bool valid = ...;
        if (valid)
            return new[] {"valid"};

        HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.NotFound);
        resp.Content = new StringContent("My custom message");
        throw new HttpResponseException(resp);
    }

请注意,如果我用“resp.Content”注释掉该行,那么一切正常。

4

1 回答 1

2
throw Request.CreateErrorResponse(HttpStatusCode.NotFound, "My custom message");
于 2012-12-05T15:42:51.213 回答