0

MVC 사이트에 맞춤 경로를 설정했습니다. 나는 리디렉션하는 방법을 알아내는 데 어려움을 겪고 있습니다. 여기MVC에서 맞춤 경로로 리디렉션

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 파일입니다 :

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 } 
     ); 
    } 
} 

것은이 제대로 작동 여기 내 사용자 지정 경로 코드입니다. 내 브라우저 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