1

MVC プロジェクトに取り組んでおり、URL の再ルーティングに苦労しています。私が現在持っているのは

http://dev.mywebsite.com/s/index?Key=abc123

次に、インデックスアクションを実行し、希望どおりに完了します。入力できるようにしたいです

http://dev.mywebsite.com/s/abc123

通常どおりインデックスアクションを実行します

私は現在持っています

        routes.MapRoute(null, "s/index/{id}", new
        {
            controller = "Home",
            action = "Index",
            id = UrlParameter.Optional
        }
             );

しかし、私はここからどこへ行くべきかについてちょっと立ち往生しています。どんな援助でも大歓迎です。ありがとう

編集: 私の完全な routeconfig クラス

routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("sites/{*pathInfo}");

        routes.MapRoute(null, "s/index/{key}", new
        {
            controller = "S",
            action = "Index",
            key = UrlParameter.Optional
        }
        );

        routes.MapRoute(
            "Default",
            "{controller}/{action}/{id}",
            new { controller = "Site", action = "Index", id = UrlParameter.Optional },
            new[] { "Custom.Web.Controllers" }
        );
    }

私のコントローラーには、actionresult インデックスがあります。

    public ActionResult Index(string Key)
    {
        return Redirect(workflow.RetrieveURL(Key));
    }
4

1 に答える 1

1

したがって、すべてのコメントの後、解決策は次のとおりです。

routes.MapRoute(null, "s/{Key}",
new {
  controller = "Home",
  action = "Index",
  Key = UrlParameter.Optional
});

このルールを他のすべてのルールの前に配置して、優先順位を付けます

于 2013-06-11T20:46:20.087 に答える