나는 이중 언어 MVC4 기능을 수행하기 위해 this answer을 추적했습니다. 나는 또한 이중 언어 인 404 오류 페이지를 만들었지 만 잘못된 링크를 입력하면 영어 버전으로 이동하거나 MVC 재고 404 페이지를 표시합니다. 나는 두 솔루션 모두를 포함하여 많은 솔루션을 시도했지만 found here,하지만 아무것도 도움이 될 것 같습니다.MVC4에서 이중 언어 404 페이지
0
A
답변
0
성공적으로 작동하도록 만들었습니다. @ r.vengadesh와 내가 질문에서 제공 한 링크 덕분입니다.
protected void Application_Error(object sender, EventArgs e)
{
Server.ClearError();
var routeData = new RouteData();
HttpContextBase currentContext = new HttpContextWrapper(HttpContext.Current);
var culture = RouteTable.Routes.GetRouteData(currentContext).Values["culture"];
routeData.Values["culture"] = culture;
routeData.Values["controller"] = "Error";
if ((Context.Server.GetLastError() is HttpException) && ((Context.Server.GetLastError() as HttpException).GetHttpCode() != 404))
{
routeData.Values["action"] = "Index";
}
else
{
Response.StatusCode = 404;
routeData.Values["action"] = "page404";
}
IController errorController = new ErrorController();
HttpContextWrapper wrapper = new HttpContextWrapper(Context);
var rc = new System.Web.Routing.RequestContext(wrapper, routeData);
errorController.Execute(rc);
}
그리고 RouteConfig : : 물론
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "DefaultWithCulture",
url: "{culture}/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
constraints: new { culture = new CultureConstraint(defaultCulture: "en", pattern: "[a-z]{2}") }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { culture = "en", controller = "Home", action = "Index", id = UrlParameter.Optional }
);
// Catch-all route (for routing misses)
routes.MapRoute(
name: "Localized-404",
url: "{culture}/{*url}",
defaults: new { controller = "Error", action = "page404" },
constraints: new { culture = new CultureConstraint(defaultCulture: "en", pattern: "[a-z]{2}") }
);
routes.MapRoute(
name: "Default-404",
url: "{*url}",
defaults: new { culture = "en", controller = "Error", action = "page404" }
);
}
}
당신이 이 필요 어쨌든, 여기에 파일 내에서 수정 ...
Global.asax에 있습니다 ErrorController 안에 페이지가 404 있습니다.
0
Global.asax에
protected void Application_Error(object sender, EventArgs e)
{
// Do whatever you want to do with the error
//Show the custom error page...
Server.ClearError();
var routeData = new RouteData();
routeData.Values["controller"] = "Error";
if ((Context.Server.GetLastError() is HttpException) && ((Context.Server.GetLastError() as HttpException).GetHttpCode() != 404))
{
routeData.Values["action"] = "Index";
}
else
{
// Handle 404 error and response code
Response.StatusCode = 404;
routeData.Values["action"] = "NotFound404";
}
Response.TrySkipIisCustomErrors = true; // If you are using IIS7, have this line
IController errorsController = new ErrorController();
HttpContextWrapper wrapper = new HttpContextWrapper(Context);
var rc = new System.Web.Routing.RequestContext(wrapper, routeData);
errorsController.Execute(rc);
}
단지 오류 컨트롤러를 작성하고 당신이보기로 이상이 입력 어떤 NotFound404보기를 만들 만들고 그 그것은 나를 위해 일한
.
관련 문제
- 1. MVC4에서 특정 언어 오류 페이지를 만듭니다.
- 2. Liferay의 언어 별 맞춤 404 페이지
- 3. 이중 언어 사이트 인덱싱
- 4. 이중 언어 브라우저 리디렉션
- 5. ASP.NET MVC 이중 언어 응용 프로그램 리소스 파일과 별도 페이지
- 6. 페이지 (404)
- 7. 404 페이지
- 8. reactjs - 404 페이지 - 언어 매개 변수에 처리 문제가 누락되었습니다.
- 9. 브라우저 언어 기반의 404 페이지 (mod_rewrite 사용 방법)
- 10. 이중 언어 사이트 용 PHP
- 11. 다국어/이중 언어 사이트로 말하기
- 12. 이중 언어 JTextArea 글꼴 변경
- 13. 리디렉션 로그인 후 페이지 제출 MVC4에서
- 14. MVC4에서 AJAX 페이지 매김으로 검색 및 정렬
- 15. 이중 언어 유비쿼터스 언어 도메인 기반 설계를 사용하여 프로젝트의
- 16. 404 오류 페이지 리디렉션
- 17. jQuery 탭로드 404 페이지
- 18. 맞춤 404 페이지 CSS?
- 19. 404 페이지 오버라이드 피하기
- 20. htaccess가있는 여러 404 페이지
- 21. Azure custom 404 페이지
- 22. 젠드 리디렉션 404 페이지
- 23. 맞춤 404 페이지 만들기
- 24. SharePoint 404 페이지
- 25. htaccess 404 페이지 포함
- 26. .htaccess rewrite = 404 페이지
- 27. 오류 페이지 생성 - 404
- 28. Redmine 404 일부 페이지
- 29. 맞춤 404 페이지
- 30. 404 페이지 IE9
시도해 본 뒤 기본 영어 404 페이지로 이동합니다. 그것은 독일어로 머 무르지 않습니다. 차이점은 주소 표시 줄에 ".....? aspxerrorpath = ....."대신 "URL을 잘못 입력하면 아무 것도 바뀌지 않습니다"입니다. Btw이 코드는 라우팅의 culture 부분 (localhost : xxxx/en/및 localhost : xxxx/de /)을 어떻게 사용 하는지를 볼 수 없습니다. – Pero93