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

So, after all our comments, the solution is:

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

Place this rule before all the others to give it preference

于 2013-06-11T20:46:20.087 回答