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
: 'http://www.myexample.com/Dashboard ' – Icemanind
問題は実際には別のものでした。これはうまくいった。 – Icemanind