本文整理汇总了C#中RouteCollection.MapHttpHandler方法的典型用法代码示例。如果您正苦于以下问题:C# RouteCollection.MapHttpHandler方法的具体用法?C# RouteCollection.MapHttpHandler怎么用?C# RouteCollection.MapHttpHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RouteCollection
的用法示例。
在下文中一共展示了RouteCollection.MapHttpHandler方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: MapHttpHandlerWithFuncSetsRouteNameAndHttpHandlerRouteHandler
public void MapHttpHandlerWithFuncSetsRouteNameAndHttpHandlerRouteHandler()
{
// Arrange
var httpHandler = new Mock<IHttpHandler>().Object;
var routes = new RouteCollection();
// Act
var route = routes.MapHttpHandler<IHttpHandler>("route-name", "url", r => httpHandler);
// Assert
PAssert.IsTrue(() => route.GetRouteName() == "route-name");
PAssert.IsTrue(() => route.RouteHandler.GetHttpHandler(null) == httpHandler);
}
示例3: MapHttpHandlerSetsRouteNameAndHttpHandlerRouteHandler
public void MapHttpHandlerSetsRouteNameAndHttpHandlerRouteHandler()
{
// Arrange
var obj = new RouteValueDictionary { { "foo", "bar" } };
var routeValues = new RouteValueDictionary(obj);
PAssert.IsTrue(() => (string)routeValues["foo"] == "bar");
var httpHandler = new Mock<IHttpHandler>().Object;
var routes = new RouteCollection();
// Act
var route = routes.MapHttpHandler("route-name", "url", httpHandler);
// Assert
PAssert.IsTrue(() => route.GetRouteName() == "route-name");
PAssert.IsTrue(() => route.RouteHandler.GetHttpHandler(null) == httpHandler);
}
示例4: RegisterRoutes
public static void RegisterRoutes(RouteCollection routes)
{
var configuration = DependencyResolver.Current.GetService<IServerConfiguration>();
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"proxy", // Route name
configuration.HgServerRoot + "/{*url}", // URL with parameters
new { controller = "Proxy", action = "ProxyRequest" } // Parameter defaults
);
routes.MapRoute(
"InfoRefs", // Route name
configuration.GitServerRoot + "/info/refs", // URL with parameters
new { Controller = "InfoRefs", Action = "Execute" } // Parameter defaults
);
routes.MapRoute(
"UploadPack", // Route name
configuration.GitServerRoot + "/git-upload-pack", // URL with parameters
new { Controller = "Rpc", Action = "UploadPack" } // Parameter defaults
);
routes.MapRoute(
"ReceivePack", // Route name
configuration.GitServerRoot + "/git-receive-pack", // URL with parameters
new { Controller = "Rpc", Action = "ReceivePack" } // Parameter defaults
);
routes.MapHttpHandler(
"DeploymentStatus",
"deploy/status/{*url}",
context => new DeploymentStatusHandler()
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}