여기에 게시 된 다른 질문은 첫 번째 질문에 대한 해결책을 제공합니다. 즉, ASP.NET MVC에서 404 페이지를 생성하는 방법입니다. WITH redirecting (즉, 원래 요청한 URL은 주소 표시 줄에 남아 있습니다).IOCControllerFactory를 사용할 때 리디렉션없이 StackOverflow와 같은 404를 던지십시오.
ASP.NET MVC - How to throw a 404 page similar to that on StackOverflow
protected void Application_Error(object sender, EventArgs e)
{
var exception = Server.GetLastError();
Response.Clear();
var httpException = exception as HttpException;
var routeData = new RouteData();
routeData.Values.Add("controller", "Error");
if (httpException != null)
{
routeData.Values.Add("action", httpException.GetHttpCode() == 404 ? "NotFound" : "Unknown");
// clear the error, otherwise, we will always get the default error page.
Server.ClearError();
// call the controller with the route
IController errorController = new ErrorController();
errorController.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));
}
}
내가을 나는이 공장을 사용하는 즉시 IOCControllerFactory 사용하지만,하지 않을 경우 것들의 (404)면이 나를 위해 잘 작동 global.asax
의 오류 코드가 아닙니다 사용 대신 내가받을 다음과 같은 오류 :
The IControllerFactory 'MyNamespace.IOCControllerFactory' did not return a controller for the name 'blah'.
어떻게 제어 방식의 각각에 대해 매개 변수가없는 생성자를 내 controllerfactory 치우는에 의존하고 생성하지 않고,이 문제를 해결받을 수 있나요 창녀?
보기 [포스트 (http://stackoverflow.com/questions/619895/how-can-i-properly-handle-404-in-asp-net-mvc/7967759#7967759), 이는 ASP.Net MVC 필터 속성을 사용하는 사용자 정의 404 오류 페이지 솔루션의 예입니다. 이 솔루션은 또한 브라우저에 대한 302/200 메시지를 피합니다. 브라우저는 404 응답을받습니다. –