私は
routes.MapRoute(
name: "Default",
url: "{custom}/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
constraints: new { custom = new RouteValidation() }
);
を次のように動作しますが、それが唯一のホーム/インデックスのために働くで自分のアプリケーションのための新しいルートを作成しました。ホーム/ログインに行きたいときは、ページをリロードするだけです。これは新しい経路の前に働いた。
私の質問は、すべての方法のための新しいルートを作成する必要がありますか、これを行うには良い方法がありますか?
更新
私は何を取得したいと思いは「カスタム」は、企業からの情報を取得するための固有のIDです。このlocalhost/{custom}/{controller}/{action}/{id}
のようなURLです。
1234 = company 'A' -> localhost/1234/Home/Index
0987 = company 'B' -> localhost/0987/Home/Index
はここに私の完全なルーティング
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Route1",
url: "{custom}/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
constraints: new { custom = new CustomerServiceModule.Helpers.RouteValidation() }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}ここで
私RouteValidationがあり、{custom}
が有効なIDであるかどうかは、このチェックで、これは動作します。
public class RouteValidation : IRouteConstraint
{
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
if (routeDirection == RouteDirection.IncomingRequest)
{
//returns true if the 'custom' is valid else false
return CheckPublicationUniqueID(values["custom"].ToString());
}
return false;
}
}
そして、ここでは、アプリケーションのいくつかの経路である
Index/Home
Index/Login
Subscription/Index
Subscription/Edit/{id}
Subscription/Details/{id}
Invoice/Index
History/Index
私が持っている問題は、私がすることができます「購読/インデックス」「カスタム」のURLからなくなっていると言うに移動した場合と、既定のルートを削除すると、上記のURLには移動しません。これはあなたのナビゲーションにあるであろう
@Html.RouteLink("LINKTEXT", new { action = "ACTION", controller = "CONTROLLER", area = "AREA IF THERE IS ONE" })
:
あなたの質問は不明です。既定のルートをこのルートに置き換えましたか、既定の "既定"ルートが存在しますか?実際にどのURLをルーティングしていますか?それは文字通り '/ Home/Index'と'/Home/Login'ですか?もしそうなら、 '{custom}'が果たす役割は何ですか? 'RouteConfig.cs'ファイル全体を投稿した方が助かります。 –
Chrisが正しいです。ルート設定全体(RotouValidation()のconstriantを含む)を投稿して、あなたの設定に*壊れているものを示してください。この設定で '/ Home/Index'に行くと、あなたは' Index'というコントローラとあなたの 'url'パラメータに基づいて' Index'という名前のアクションに行くことを示しています)。 – NightOwl888