문제

나는 내 자신의 예외 필터를 만들려고 노력하고 있습니다. 상자에서 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>

좋아 - 말이 안 돼요. 제가하려는 일을 설명하기 위해 코드를 보자 ... 그런 다음 ...

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