鉴于以下配置,ServiceStack将呈现notfound
razor视图,并在发生NotFound错误时返回200状态代码。
如何使用RazorHandler
呈现notfound
视图并保留正确的404状态代码?
SetConfig(new EndpointHostConfig {
CustomHttpHandlers = {
{ HttpStatusCode.NotFound, new RazorHandler("/notfound") },
{ HttpStatusCode.Unauthorized, new RazorHandler("/login") },
}
});
答案 0 :(得分:2)
notfound.cshtml:
@{
this.Layout = "_YourLayout";
this.Response.StatusCode = 404;
}