0

Web サイトのユーザーが独自のバニティ URL を指定して変更できるようにしようとしています。

選択した URL をデータベースに保存し、それを呼び出してユーザーに再ルーティングします。

今のところこれは私が持っているものですが、ここからどこへ行くべきか本当にわかりません.

routes.MapRoute(
            "User", // Route name
            "User/Profile/{id}", // URL with parameters
            new { controller = "User", action = "Profile", id = UrlParameter.Optional }, // Parameter defaults
            new string[] { typeof(MvcApplication).Namespace + ".Controllers" }
        );

バニティ URL を取得して PersonID に再ルーティングする方法はありますか?

また、ActionResult を操作して文字列 Vanity Url または int PersonID を処理しようとしましたが、正しい方向に進んでいないように見えたので、routes.Maproute に戻りました。

編集:

ユーザーが入力できるようにしたい

http://localhost:60619/User/Profile/Vanity 

入ったときと同じ場所にたどり着きます

http://localhost:60619/User/Profile/224 Assuming the PersonID is 224

アクション結果:

        public ActionResult Profile(int ID)
    {
        ppUser viewerChoice = DB.ppUser_GetUserByPersonID(ID);
        return View(ID);
    }
4

2 に答える 2

0

以下のコードを使用することで、2 つの異なるページを 1 つのドメインに配置することができます。

    protected void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes(RouteTable.Routes);
    }

    public static void RegisterRoutes(RouteCollection routeCollection)
    {
        routeCollection.MapPageRoute("RouteForCustomer", "{Id}", "~/User.aspx");
        routeCollection.MapPageRoute("RouteForCustomer", "Home", "~/Default.aspx");
    }
于 2012-10-10T10:33:33.940 に答える