0

MVCサイトにカスタムルートをセットアップしました。私はそれにリダイレクトする方法を考え出すのに困っている。ここに私のカスタムルートコードは次のとおりです。MVCのカスタムルートにリダイレクト

public class RouteConfig 
{ 
    public static void RegisterRoutes(RouteCollection routes) 
    { 
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 


     routes.MapRoute(
     name: "MembersRoute", 
     url: "{*permalink}", 
     defaults: new { controller = "Dashboard", action = "Index" }, 
     constraints: new { permalink = new MemberUrlConstraint() }); 

     routes.MapRoute(
      name: "Default", 
      url: "{controller}/{action}/{id}", 
      defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
     ); 
    } 
} 

これが正常に動作している:

public class MemberUrlConstraint : IRouteConstraint 
{ 
    public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, 
     RouteDirection routeDirection) 
    { 
     if (values[parameterName] != null) 
     { 
      var permalink = values[parameterName].ToString(); 

      return string.Equals(permalink, Member.GetAuthenticatedMembersUrl(), 
       StringComparison.OrdinalIgnoreCase); 
     } 
     return false; 
    } 
} 

ここに私のRouteConfig.csファイルです。私がブラウザのURLにhttp://www.example.com/Joes-Pageのようなものを置くとうまくいきます。

私の質問は、プログラムでこのページにリダイレクトする方法です。私はこの試みた:

RedirectToAction("Index", "Dashboard"); // Goes to http://www.myexample.com/Dashboard 

RedirectToRoute("MembersRoute", new {controller = Infrastructure.Member.GetAuthenticatedMembersUrl(), action = "Index"}); // Goes to http://www.myexample.com/Home/Index 

は、私が試してみてくださいhttp://www.example.com/Joes-Page

答えて

1

にリダイレクトできるようにしたい

RedirectToAction("Index", "Dashboard", new { permalink = "Joes-Page"}); 
ここに連れて行ってくれました
+0

: 'http://www.myexample.com/Dashboard ' – Icemanind

+0

問題は実際には別のものでした。これはうまくいった。 – Icemanind

関連する問題