機能しているバイリンガル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. 404ページ
- 2. は、404ページの
- 3. Laravelローカライズ404ページで
- 4. ポストメソッドin asp.net mvc4他のページへ
- 5. カスタム404ページ(
- 6. Permalink 404ページへ
- 7. カスタム404ページcss?
- 8. Drupal 404ページ
- 9. Railsブドウショー404ページ
- 10. ページネーションは、404ページ
- 11. CodeIgniterで404ページを表示
- 12. WordPressで静的404ページ
- 13. Asp.Net MVC4 + Web APIコントローラ削除要求>> 404エラー
- 14. MVC4 cshtmlページ関数呼び出し
- 15. Akka-httpカスタム404ページ
- 16. スプリングmvc:ダイナミック404ページ
- 17. Yii2サイト/ページ404エラー
- 18. .htaccessのページの再ルーティング - 404
- 19. CodeIgniter 404ページのSuSeのルート
- 20. Google Assistantのバイリンガル話し刺しカード
- 21. バイリンガル/多言語入力環境のアクセラレータキー
- 22. ワードプレスのページを返す404
- 23. ページ404の場合、301?
- 24. エラー404のページにリダイレクト
- 25. ASP.NET MVCアプリケーション用の404ページ
- 26. jQueryタブのロード404ページ
- 27. アプリケーションキャッシュ&500分の404ページ
- 28. ワードプレスで404ページのURLを取得
- 29. MVC4ソートで現在のページ番号を送信するには?
- 30. - MVC4
これを試してみて、デフォルトの英語404ページに移動します。それはドイツ語ではありません。差異だけです:アドレスバーに、間違ったURLを置いた後に何も変わらず、 ".....?aspxerrorpath = ....."と表示されます。 Btw私はどのようにこのコードは、ルーティング(localhost:xxxx/en /とlocalhost:xxxx/de /)の文化の部分を使用しているか分かりません。 – Pero93