1

给定以下配置,ServiceStack 将呈现notfound剃刀视图并在发生 NotFound 错误时返回 200 状态代码。

如何使用RazorHandler来呈现notfound视图并保持正确的 404 状态代码?

SetConfig(new EndpointHostConfig {
    CustomHttpHandlers = {
        { HttpStatusCode.NotFound, new RazorHandler("/notfound") },
        { HttpStatusCode.Unauthorized, new RazorHandler("/login") },
    }
});
4

1 回答 1

2

notfound.cshtml:

@{
  this.Layout = "_YourLayout";
  this.Response.StatusCode = 404;
} 
于 2013-06-03T21:39:28.663 回答