本文整理汇总了C#中RouteCollection.Redirect方法的典型用法代码示例。如果您正苦于以下问题:C# RouteCollection.Redirect方法的具体用法?C# RouteCollection.Redirect怎么用?C# RouteCollection.Redirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RouteCollection
的用法示例。
在下文中一共展示了RouteCollection.Redirect方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterRoutes
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// Redirect From Old Route to New route
var targetRoute = routes.Map("target", "yo/{id}/{action}", new { controller = "Home" });
routes.Redirect(r => r.MapRoute("legacy", "foo/{id}/baz/{action}")).To(targetRoute, new { id = "123", action = "index" });
routes.Redirect(r => r.MapRoute("legacy2", "foo/baz")).To(targetRoute, new { id = "123", action = "index" });
// Map Delegate
routes.MapDelegate("map-delegate", "this-is-a-test", rc => rc.HttpContext.Response.Write("Yeah, it's a test"));
routes.MapDelegate("map-delegate-incoming-only", "this-is-a-test", new { whatever = new IncomingOnlyRouteConstraint() }, rc => rc.HttpContext.Response.Write("Yeah, it's a test"));
// Map HTTP Handlers
routes.MapHttpHandler<HelloWorldHttpHandler>("hello-world", "handlers/helloworld");
routes.MapHttpHandler("hello-world2", "handlers/helloworld2", new HelloWorldHttpHandler());
RouteCollection someRoutes = new RouteCollection();
someRoutes.MapHttpHandler<HelloWorldHttpHandler>("hello-world3", "handlers/helloworld3");
someRoutes.MapHttpHandler("hello-world4", "handlers/helloworld4", new HelloWorldHttpHandler());
var groupRoute = new GroupRoute("~/section", someRoutes);
routes.Add("group", groupRoute);
var mvcRoutes = new RouteCollection();
mvcRoutes.Map("foo1", "foo/{controller}", new { action = "index" });
mvcRoutes.Map("foo2", "foo2/{controller}", new { action = "index" });
routes.Add("group2", new GroupRoute("~/group2sec", mvcRoutes));
var defaultRoute = routes.Map(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
).SetRouteName("Default");
}
示例2: Redirect_WithNullSourceRouteMapping_ThrowsArgumentNullException
public void Redirect_WithNullSourceRouteMapping_ThrowsArgumentNullException()
{
// arrange
var targetRoute = new Mock<RouteBase>().Object;
RouteCollection routes = new RouteCollection();
// Act, Assert
Assert.Throws<ArgumentNullException>(() => routes.Redirect(null));
}
示例3: RegisterRoutes
/// <summary>
/// Registers the routes.
/// </summary>
/// <param name="routes">The routes.</param>
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// old routes, permenant redirects
var homeRoute = routes.MapRoute("Home", "Home", new { controller = "Home", action = "Index", id = UrlParameter.Optional });
var aboutRoute = routes.MapRoute("About", "About", new { controller = "Home", action = "About", id = UrlParameter.Optional });
var resumeRoute = routes.MapRoute("Resume", "Resume", new { controller = "Home", action = "Resume", id = UrlParameter.Optional });
routes.Redirect(r => r.MapRoute("oldHome", "Home"), true).To(homeRoute);
routes.Redirect(r => r.MapRoute("oldAboutMe", "AboutMe"), true).To(aboutRoute);
routes.Redirect(r => r.MapRoute("oldAboutSite", "AboutSite"), true).To(aboutRoute);
routes.Redirect(r => r.MapRoute("oldResume", "Resume"), true).To(resumeRoute);
routes.Redirect(r => r.MapRoute("oldProjects", "Projects"), true).To(homeRoute);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });
}
示例4: Redirect_WithRouteMappingFunc_DoesNotAddRouteToMainRoutes
public void Redirect_WithRouteMappingFunc_DoesNotAddRouteToMainRoutes() {
// Arrange
var routes = new RouteCollection();
var targetRoute = new Mock<RouteBase>().Object;
// Act
var redirectRoute = routes.Redirect(r => r.Map("test", "testurl")).To(targetRoute);
// Assert
PAssert.IsTrue(() => routes.Count == 1);
PAssert.IsTrue(() => routes[0] is NormalizeRoute);
}
示例5: Redirect_SourceRouteButNoTarget_ReturnsPartialRedirectRoute
public void Redirect_SourceRouteButNoTarget_ReturnsPartialRedirectRoute() {
// Arrange
var routes = new RouteCollection();
var sourceRoute = new Mock<RouteBase>().Object;
// Act
var redirectRoute = routes.Redirect(r => sourceRoute, permanent: true);
// Assert
PAssert.IsTrue(() => redirectRoute.SourceRoute == sourceRoute);
PAssert.IsTrue(() => redirectRoute.TargetRoute == null);
PAssert.IsTrue(() => redirectRoute.Permanent == true);
}
示例6: RegisterRoutes
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//http://haacked.com/archive/2011/02/02/redirecting-routes-to-maintain-persistent-urls.aspx
var images = routes.MapRoute("content_images", "content/images/{file}");
routes.Redirect(r => r.MapRoute("moth_images", "resources/images/{file}"))
.To(images);
// routes.MapHttpRoute(
// name: "DefaultApi",
// routeTemplate: "api/{controller}/{id}",
// defaults: new { id = RouteParameter.Optional }
// );
routes.MapRoute(
name: null,
url: "login",
defaults: new { controller = "Account", action = "Login", performanceId = UrlParameter.Optional }
);
routes.MapRoute(
name: null,
url: "logoff",
defaults: new { controller = "Account", action = "LogOff", performanceId = UrlParameter.Optional }
);
routes.MapRoute(
name: null,
url: "summary/{performanceId}",
defaults: new { controller = "Scoring", action = "Summary", performanceId = UrlParameter.Optional }
);
routes.MapRoute(
name: null,
url: "entry/{performanceId}/judges-{judgeId}",
defaults: new { controller = "Scoring", action = "ScoreEntry" }
);
routes.MapRoute(
name: null,
url: "performances/{id}",
defaults: new { controller = "Performance", action = "Index" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Landing", action = "Index", id = UrlParameter.Optional }
);
}
示例7: Redirect_SourceAndTarget_ReturnsRedirectRoute
public void Redirect_SourceAndTarget_ReturnsRedirectRoute() {
// Arrange
var routes = new RouteCollection();
var sourceRoute = new Mock<RouteBase>().Object;
var targetRoute = new Mock<RouteBase>().Object;
// Act
var redirectRoute = routes.Redirect(r => sourceRoute, permanent: false).To(targetRoute);
// Assert
PAssert.IsTrue(() => redirectRoute.SourceRoute == sourceRoute);
PAssert.IsTrue(() => redirectRoute.TargetRoute == targetRoute);
PAssert.IsTrue(() => redirectRoute.Permanent == false);
}
示例8: RegisterUIRoutes
//.........这里部分代码省略.........
version = UrlParameter.Optional
},
new { version = new VersionRouteConstraint() });
routes.MapRoute(
RouteName.PackageEnableLicenseReport,
"packages/{id}/{version}/EnableLicenseReport",
new { controller = "Packages", action = "SetLicenseReportVisibility", visible = true },
new { version = new VersionRouteConstraint() });
routes.MapRoute(
RouteName.PackageDisableLicenseReport,
"packages/{id}/{version}/DisableLicenseReport",
new { controller = "Packages", action = "SetLicenseReportVisibility", visible = false },
new { version = new VersionRouteConstraint() });
var packageVersionActionRoute = routes.MapRoute(
RouteName.PackageVersionAction,
"packages/{id}/{version}/{action}",
new { controller = "Packages" },
new { version = new VersionRouteConstraint() });
var packageActionRoute = routes.MapRoute(
RouteName.PackageAction,
"packages/{id}/{action}",
new { controller = "Packages" });
var confirmationRequiredRoute = routes.MapRoute(
"ConfirmationRequired",
"account/ConfirmationRequired",
new { controller = "Users", action = "ConfirmationRequired" });
//Redirecting v1 Confirmation Route
routes.Redirect(
r => r.MapRoute(
"v1Confirmation",
"Users/Account/ChallengeEmail")).To(confirmationRequiredRoute);
routes.MapRoute(
RouteName.ExternalAuthenticationCallback,
"users/account/authenticate/return",
new { controller = "Authentication", action = "LinkExternalAccount" });
routes.MapRoute(
RouteName.ExternalAuthentication,
"users/account/authenticate/{provider}",
new { controller = "Authentication", action = "Authenticate" });
routes.MapRoute(
RouteName.Authentication,
"users/account/{action}",
new { controller = "Authentication" });
routes.MapRoute(
RouteName.Profile,
"profiles/{username}",
new { controller = "Users", action = "Profiles" });
routes.MapRoute(
RouteName.LegacyRegister,
"account/register",
new { controller = "Authentication", action = "Register" });
routes.MapRoute(
RouteName.RemovePassword,
"account/RemoveCredential/password",
示例9: RegisterRoutes
//.........这里部分代码省略.........
new { controller = MVC.Packages.Name, action = "CancelUpload"});
routes.MapRoute(
RouteName.PackageOwnerConfirmation,
"packages/{id}/owners/{username}/confirm/{token}",
new { controller = MVC.Packages.Name, action = "ConfirmOwner" });
// We need the following two routes (rather than just one) due to Routing's
// Consecutive Optional Parameter bug. :(
var packageDisplayRoute = routes.MapRoute(
RouteName.DisplayPackage,
"packages/{id}/{version}",
MVC.Packages.DisplayPackage().AddRouteValue("version", UrlParameter.Optional),
null /*defaults*/,
new { version = new VersionRouteConstraint() });
var packageVersionActionRoute = routes.MapRoute(
RouteName.PackageVersionAction,
"packages/{id}/{version}/{action}",
new { controller = MVC.Packages.Name },
new { version = new VersionRouteConstraint() });
var packageActionRoute = routes.MapRoute(
RouteName.PackageAction,
"packages/{id}/{action}",
new { controller = MVC.Packages.Name });
var resendRoute = routes.MapRoute(
"ResendConfirmation",
"account/ResendConfirmation",
MVC.Users.ResendConfirmation());
//Redirecting v1 Confirmation Route
routes.Redirect(
r => r.MapRoute(
"v1Confirmation",
"Users/Account/ChallengeEmail")).To(resendRoute);
routes.MapRoute(
RouteName.Authentication,
"users/account/{action}",
new { controller = MVC.Authentication.Name });
routes.MapRoute(
RouteName.Profile,
"profiles/{username}",
MVC.Users.Profiles());
routes.MapRoute(
RouteName.PasswordReset,
"account/{action}/{username}/{token}",
MVC.Users.ResetPassword());
routes.MapRoute(
RouteName.Account,
"account/{action}",
MVC.Users.Account());
routes.MapRoute(
RouteName.CuratedFeed,
"curated-feeds/{name}",
new { controller = CuratedFeedsController.ControllerName, action = "CuratedFeed" });
routes.MapRoute(
RouteName.CuratedFeedListPackages,
"curated-feeds/{curatedFeedName}/packages",
示例10: RegisterRoutes
/// <summary>
/// Registers the routes.
/// </summary>
/// <param name="routes">The routes.</param>
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("virto/services/{MyJob}.svc/{*pathInfo}");
routes.IgnoreRoute("virto/dataservices/{MyJob}.svc/{*pathInfo}");
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute(".html");
//Ignore all calls to bundles
routes.IgnoreRoute("bundles/{*pathInfo}");
//Ignore all calls to areas (Areas supposed to serve own routes)
routes.IgnoreRoute("areas/{*pathInfo}");
//This makes sure index.html (or any other deafult document is opened for empty url
routes.IgnoreRoute("");
routes.MapRoute(
"FailWhale",
"FailWhale/{action}/{id}", new { controller = "Error", action = "FailWhale", id = UrlParameter.Optional });
routes.MapRoute(
"Assets",
"asset/{*path}",
new { controller = "Asset", action = "Index", path = UrlParameter.Optional });
var itemRoute = new NormalizeRoute(
new ItemRoute(Constants.ItemRoute,
new RouteValueDictionary
{
{"controller", "Catalog"},
{"action", "DisplayItem"},
{Constants.Language, UrlParameter.Optional}
},
new RouteValueDictionary
{
{Constants.Language, new LanguageRouteConstraint()},
{Constants.Store, new StoreRouteConstraint()},
{Constants.Category, new CategoryRouteConstraint()},
{Constants.Item, new ItemRouteConstraint()}
},
new RouteValueDictionary { { "namespaces", new[] { "VirtoCommerce.Web.Controllers" } } },
new MvcRouteHandler()));
var categoryRoute = new NormalizeRoute(
new CategoryRoute(Constants.CategoryRoute,
new RouteValueDictionary
{
{"controller", "Catalog"},
{"action", "Display"},
{Constants.Language, UrlParameter.Optional}
},
new RouteValueDictionary
{
{Constants.Language, new LanguageRouteConstraint()},
{Constants.Store, new StoreRouteConstraint()},
{Constants.Category, new CategoryRouteConstraint()}
},
new RouteValueDictionary { { "namespaces", new[] { "VirtoCommerce.Web.Controllers" } } },
new MvcRouteHandler()));
var storeRoute = new NormalizeRoute(
new StoreRoute(Constants.StoreRoute,
new RouteValueDictionary
{
{"controller", "Home"},
{"action", "Index"}
},
new RouteValueDictionary
{
{Constants.Language, new LanguageRouteConstraint()},
{Constants.Store, new StoreRouteConstraint()}
},
new RouteValueDictionary { { "namespaces", new[] { "VirtoCommerce.Web.Controllers" } } },
new MvcRouteHandler()));
routes.Add("Item", itemRoute);
routes.Add("Category", categoryRoute);
routes.Add("Store", storeRoute);
//Legacy redirects
routes.Redirect(r => r.MapRoute("old_Category", string.Format("c/{{{0}}}", Constants.Category))).To(categoryRoute,
x =>
{
//Expect to receive category code
if (x.RouteData.Values.ContainsKey(Constants.Category))
{
var category = CatalogHelper.CatalogClient.GetCategory(x.RouteData.Values[Constants.Category].ToString());
if (category != null)
{
return new RouteValueDictionary { { Constants.Category, category.CategoryId } };
}
}
return null;
});
routes.Redirect(r => r.MapRoute("old_Item", string.Format("p/{{{0}}}", Constants.Item))).To(itemRoute,
x =>
{
//.........这里部分代码省略.........
示例11: RegisterRoutes
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
RouteName.Home,
"",
MVC.Pages.Home());
routes.Add(new JsonRoute("json/{controller}"));
routes.MapRoute(
RouteName.Policies,
"policies/{action}",
MVC.Pages.Terms());
var packageListRoute = routes.MapRoute(
RouteName.ListPackages,
"packages",
MVC.Packages.ListPackages());
routes.MapRoute(
RouteName.UploadPackage,
"upload/package",
MVC.Packages.UploadPackage());
// We need the following two routes (rather than just one) due to Routing's
// Consecutive Optional Parameter bug. :(
var packageDisplayRoute = routes.MapRoute(
RouteName.DisplayPackage,
"packages/{id}/{version}",
MVC.Packages.DisplayPackage().AddRouteValue("version", UrlParameter.Optional),
null /*defaults*/,
new { version = new VersionRouteConstraint() });
var packageVersionActionRoute = routes.MapRoute(
RouteName.PackageVersionAction,
"packages/{id}/{version}/{action}",
new { controller = MVC.Packages.Name },
new { version = new VersionRouteConstraint() });
var packageActionRoute = routes.MapRoute(
RouteName.PackageAction,
"packages/{id}/{action}",
new { controller = MVC.Packages.Name });
routes.MapRoute(
RouteName.Authentication,
"users/account/{action}",
new { controller = MVC.Authentication.Name });
routes.MapRoute(
RouteName.Profile,
"profiles/{username}",
MVC.Users.Profiles());
routes.MapRoute(
RouteName.PasswordReset,
"account/{action}/{username}/{token}",
MVC.Users.ResetPassword());
routes.MapRoute(
RouteName.Account,
"account/{action}",
MVC.Users.Account());
routes.MapRoute(
RouteName.PushPackageApi,
"PackageFiles/{apiKey}/nupkg",
MVC.Api.CreatePackage());
routes.MapRoute(
RouteName.PublishPackageApi,
"PublishedPackages/Publish",
MVC.Api.PublishPackage());
routes.MapRoute(
RouteName.DeletePackageApi,
"Packages/{apiKey}/{id}/{version}",
MVC.Api.DeletePackage());
routes.MapServiceRoute(
RouteName.V1ApiFeed,
"api/feeds/v1",
typeof(V1Feed));
routes.MapServiceRoute(
RouteName.V2ApiFeed,
"api/feeds/v2",
typeof(V2Feed));
routes.MapServiceRoute(
RouteName.ApiFeed,
"api/feeds",
typeof(V2Feed));
// Redirected Legacy Routes
routes.Redirect(
r => r.MapRoute(
"ReportAbuse",
"Package/ReportAbuse/{id}/{version}",
//.........这里部分代码省略.........
示例12: RegisterRoutes
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
RouteName.Home,
"",
MVC.Pages.Home());
routes.Add(new JsonRoute("json/{controller}"));
routes.MapRoute(
RouteName.Policies,
"policies/{action}",
MVC.Pages.Terms());
var packageListRoute = routes.MapRoute(
RouteName.ListPackages,
"packages",
MVC.Packages.ListPackages());
var uploadPackageRoute = routes.MapRoute(
RouteName.UploadPackage,
"packages/upload",
MVC.Packages.UploadPackage());
routes.MapRoute(
RouteName.VerifyPackage,
"packages/verify-upload",
MVC.Packages.VerifyPackage());
routes.MapRoute(
RouteName.CancelUpload,
"packages/cancel-upload",
MVC.Packages.CancelUpload());
routes.MapRoute(
RouteName.PackageOwnerConfirmation,
"packages/{id}/owners/{username}/confirm/{token}",
new { controller = MVC.Packages.Name, action = "ConfirmOwner" });
// We need the following two routes (rather than just one) due to Routing's
// Consecutive Optional Parameter bug. :(
var packageDisplayRoute = routes.MapRoute(
RouteName.DisplayPackage,
"packages/{id}/{version}",
MVC.Packages.DisplayPackage().AddRouteValue("version", UrlParameter.Optional),
null /*defaults*/,
new { version = new VersionRouteConstraint() });
var packageVersionActionRoute = routes.MapRoute(
RouteName.PackageVersionAction,
"packages/{id}/{version}/{action}",
new { controller = MVC.Packages.Name },
new { version = new VersionRouteConstraint() });
var packageActionRoute = routes.MapRoute(
RouteName.PackageAction,
"packages/{id}/{action}",
new { controller = MVC.Packages.Name });
var resendRoute = routes.MapRoute(
"ResendConfirmation",
"account/ResendConfirmation",
MVC.Users.ResendConfirmation());
//Redirecting v1 Confirmation Route
routes.Redirect(
r => r.MapRoute(
"v1Confirmation",
"Users/Account/ChallengeEmail")).To(resendRoute);
routes.MapRoute(
RouteName.Authentication,
"users/account/{action}",
new { controller = MVC.Authentication.Name });
routes.MapRoute(
RouteName.Profile,
"profiles/{username}",
MVC.Users.Profiles());
routes.MapRoute(
RouteName.PasswordReset,
"account/{action}/{username}/{token}",
MVC.Users.ResetPassword());
routes.MapRoute(
RouteName.Account,
"account/{action}",
MVC.Users.Account());
// TODO : Most of the routes are essentially of the format api/v{x}/*. We should refactor the code to vary them by the version.
// V1 Routes
// If the push url is /api/v1 then NuGet.Core would ping the path to resolve redirection.
routes.MapServiceRoute(
RouteName.V1ApiFeed,
"api/v1/FeedService.svc",
typeof(V1Feed));
routes.MapServiceRoute(
"LegacyFeedService",
//.........这里部分代码省略.........
示例13: RegisterRoutes
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
routes.IgnoreRoute("{*Content}", new { imgs = @"(.*/)?Content(/.*)?" });
routes.IgnoreRoute("{*Scripts}", new { scripts = @"(.*/)?Scripts(/.*)?" });
routes.MapRoute(RouteName.Home, "", MVC.Pages.Home());
routes.MapRoute(
RouteName.About, "about", new
{
controller = "Pages",
Action = "About"
});
routes.MapRoute(
RouteName.InstallerBatchFile, "installChocolatey.cmd", new
{
controller = "Pages",
Action = "InstallerBatchFile"
});
routes.MapRoute(
RouteName.Notice, "notice", new
{
controller = "Pages",
Action = "Notice"
});
routes.MapRoute(RouteName.Stats, "stats", MVC.Pages.Stats());
routes.MapRoute(
"rss feed", "feed.rss", new
{
controller = "RSS",
Action = "feed.rss"
});
routes.Add(new JsonRoute("json/{controller}"));
routes.MapRoute(RouteName.Policies, "policies/{action}", MVC.Pages.Terms());
var packageListRoute = routes.MapRoute(RouteName.ListPackages, "packages", MVC.Packages.ListPackages());
routes.MapRoute(
RouteName.NotifyComment, "packages/{packageId}/notify-comment", new
{
controller = MVC.Packages.Name,
action = "NotifyMaintainersOfAddedComment"
});
var uploadPackageRoute = routes.MapRoute(RouteName.UploadPackage, "packages/upload", MVC.Packages.UploadPackage());
routes.MapRoute(RouteName.VerifyPackage, "packages/verify-upload", MVC.Packages.VerifyPackage());
routes.MapRoute(RouteName.CancelUpload, "packages/cancel-upload", MVC.Packages.CancelUpload());
routes.MapRoute(
RouteName.PackageOwnerConfirmation, "packages/{id}/owners/{username}/confirm/{token}", new
{
controller = MVC.Packages.Name,
action = "ConfirmOwner"
});
// We need the following two routes (rather than just one) due to Routing's
// Consecutive Optional Parameter bug. :(
var packageDisplayRoute = routes.MapRoute(
RouteName.DisplayPackage, "packages/{id}/{version}", MVC.Packages.DisplayPackage().AddRouteValue("version", UrlParameter.Optional), null /*defaults*/, new
{
version = new VersionRouteConstraint()
});
var packageVersionActionRoute = routes.MapRoute(
RouteName.PackageVersionAction, "packages/{id}/{version}/{action}", new
{
controller = MVC.Packages.Name
}, new
{
version = new VersionRouteConstraint()
});
var packageActionRoute = routes.MapRoute(
RouteName.PackageAction, "packages/{id}/{action}", new
{
controller = MVC.Packages.Name
});
var resendRoute = routes.MapRoute("ResendConfirmation", "account/ResendConfirmation", MVC.Users.ResendConfirmation());
//Redirecting v1 Confirmation Route
routes.Redirect(r => r.MapRoute("v1Confirmation", "Users/Account/ChallengeEmail")).To(resendRoute);
routes.MapRoute(
RouteName.Authentication, "users/account/{action}", new
{
controller = MVC.Authentication.Name
});
routes.MapRoute(RouteName.Profile, "profiles/{username}", MVC.Users.Profiles());
//.........这里部分代码省略.........