答案 0 :(得分:0)
也许您可以使用iis的Application_EndRequest事件。
protected void Application_EndRequest(object sender, EventArgs e)
{
// you could decide whether to redirect according to the path and status code
string path = HttpContext.Current.Request.Path;
if (HttpContext.Current.Response.StatusCode == 400)
{
HttpContext.Current.Response.Redirect("/ErrorPage.aspx");
}
}
请不要忘记确保wcf在兼容模式下运行。
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"></serviceHostingEnvironment>
服务之上
[AspNetCompatibilityRequirements(RequirementsMode =AspNetCompatibilityRequirementsMode.Allowed)]
public class CalculatorService : ICalculatorService
否则,Application_EndRequest事件将不会触发。