質問

私は独自のExceptionFilterを作成しようとしています。すぐに使えるASP.NET MVCには、[HandleError]属性が付属しています。これは素晴らしい->ただし、HTMLエラービューが返されます。

そのため、jsonエラーメッセージを返したいと思います。だから私は自分で作っています。

今、私のURLをテストするまで、すべてがうまく機能します。エラーが発生し続けます。これはメッセージです。...

C:\Temp\curl-7.19.5>curl -i http://localhost:6969/search/foo?name=1234&key=test1xxx
HTTP/1.1 401 Unauthorized
Server: ASP.NET Development Server/9.0.0.0
Date: Mon, 14 Sep 2009 01:54:52 GMT
X-AspNet-Version: 2.0.50727
X-AspNetMvc-Version: 1.0
Cache-Control: private
Content-Type: application/json; charset=utf-8
Content-Length: 6
Connection: Close


"Hi StackOverflow"'key' is not recognized as an internal or external command,
operable program or batch file.

C:\Temp\curl-7.19.5>

OK-それは意味がありません。次に、私がやろうとしていることを説明するコードを見てみましょう...

public class HandleErrorAsJson : FilterAttribute, IExceptionFilter
{
    public void OnException(ExceptionContext filterContext)
    {
        // Snip normal checks and stuff...

        // Assume we've figured out the type of error this is.
        // I'm going to hardcode it here, right now.
        int statusCode = 401;
        string message = "Hi StackOverflow";

        // Now prepare our json output.
        filterContext.Result = new JsonResult
            {
                Data = message
            };

        // Prepare the response code.
        filterContext.ExceptionHandled = true;
        filterContext.HttpContext.Response.Clear();
        filterContext.HttpContext.Response.StatusCode = statusCode;
    }
}

だからそれは私のコードです....それはかなり動作していますが、動作していません。

この「鍵」とはどういう意味ですか?私は何を逃しましたか、何をしようとしていますか?

助けてください!

役に立ちましたか?

解決

答えが見つかりました-> URLを" .."に入れなければなりませんでした。 (引用符)それ以外の場合は、アンパサンド記号の後のものをコマンドまたは何かとして実行しようとします。

理由はわかりませんが、それで修正されます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top