ServiceStack 不显示 404 的详细消息
ServiceStack does not show detailed message for 404
public HttpResult GET(QueryMetadataRequest request)
{
throw HttpError.NotFound("MY MESSAGE GOES HERE");
//....
}
如上抛出异常。我没有在错误页面中看到我的消息。
Handler for Request not found:
Request.HttpMethod: GET Request.PathInfo: /metadata/fefe/dsd
Request.QueryString: Request.RawUrl: /metadata/fefe/dsd
如何让ServiceStackreturn详细的404错误信息?
消息应该进入 HTTP 响应状态描述,您看到的页面是 ServiceStack 内置的默认 404 HttpHandler
,用于 HTML 页面请求(例如来自浏览器)。如果从数据格式调用,例如:
/metadata/fefe/dsd.json
/metadata/fefe/dsd?format=json
您应该看到 return 发送给 ajax 客户端的结构化错误响应。
当不在 DebugMode the 404 page emits limited information by design. I've just added a commit that will expand the page to include the Error Message if provided available from next v4.0.37+ release which is now available on MyGet.
您可以删除 ServiceStack AppHost 中的内置 404 处理程序:
CustomErrorHttpHandlers[HttpStatusCode.NotFound] = null;
或添加您自己的:
CustomErrorHttpHandlers[HttpStatusCode.NotFound] =
new RazorHandler("/404");
这将使您 return 自定义 Razor 页面,例如/404.cshtml
public HttpResult GET(QueryMetadataRequest request)
{
throw HttpError.NotFound("MY MESSAGE GOES HERE");
//....
}
如上抛出异常。我没有在错误页面中看到我的消息。
Handler for Request not found:
Request.HttpMethod: GET Request.PathInfo: /metadata/fefe/dsd Request.QueryString: Request.RawUrl: /metadata/fefe/dsd
如何让ServiceStackreturn详细的404错误信息?
消息应该进入 HTTP 响应状态描述,您看到的页面是 ServiceStack 内置的默认 404 HttpHandler
,用于 HTML 页面请求(例如来自浏览器)。如果从数据格式调用,例如:
/metadata/fefe/dsd.json
/metadata/fefe/dsd?format=json
您应该看到 return 发送给 ajax 客户端的结构化错误响应。
当不在 DebugMode the 404 page emits limited information by design. I've just added a commit that will expand the page to include the Error Message if provided available from next v4.0.37+ release which is now available on MyGet.
您可以删除 ServiceStack AppHost 中的内置 404 处理程序:
CustomErrorHttpHandlers[HttpStatusCode.NotFound] = null;
或添加您自己的:
CustomErrorHttpHandlers[HttpStatusCode.NotFound] =
new RazorHandler("/404");
这将使您 return 自定义 Razor 页面,例如/404.cshtml