1

Windsor ASP.NETMVCWebAPIプロジェクトのセットアップは次のようになっています。

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

コントローラがOKステータスを返すと、すべて正常に動作します。ただし、NotFoundなどのエラーステータスを送信しようとすると、次のエラーが発生します。

Castle.MicroKernel.Lifestyle.Scoped.CallContextLifetimeScope + SerializationReference、Castle.Windsor、Version = 3.1.0.0、Culture = neutral、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 に答える