asp.net-routing

ASP.NET MVC: Routing hierarchy URL

心已入冬 提交于 2019-12-22 09:02:24
问题 How can I make routing for this? URL: /category/main/sub/ or /category/main/sub1/subsub/ I want to have /main/sub/ and /main/sub1/subsub/ as parameters in Index action method of CategoryController. 回答1: Found the answer: Should use "/category/{*path}" instead of "/category/{path}" in the routing path. 来源: https://stackoverflow.com/questions/1588175/asp-net-mvc-routing-hierarchy-url

Do WebApi 2 and MVC 5 user different routing attributes?

↘锁芯ラ 提交于 2019-12-22 05:16:31
问题 Reading through this blog post on attribute routing in ASP.NET MVC 5 and this one on attribute routing in Web Api 2, it looks like there are two sets of routing attributes, one in the System.Web.Mvc namespace and the other in System.Web.Http . Is that right and does anyone have any idea (links) as to why it was designed this way? Should one be used over the other or are they supposed to live side by side? 回答1: Yes, these route attributes are intentionally different since Web API and MVC have

How to create RouteUrls with databound parameters declaratively?

雨燕双飞 提交于 2019-12-21 17:56:42
问题 I'm using the new Routing feature in ASP.NET 4 (Web forms, not MVC). Now I have an asp:ListView which is bound to a datasource. One of the properties is a ClientID which I want to use to link from the ListView items to another page. In global.asax I have defined a route: System.Web.Routing.RouteTable.Routes.MapPageRoute("ClientRoute", "MyClientPage/{ClientID}", "~/Client.aspx"); so that for instance http://server/MyClientPage/2 is a valid URL if ClientID=2 exists. In the ListView items I have

How do I route images through ASP.NET routing?

自闭症网瘾萝莉.ら 提交于 2019-12-20 23:23:57
问题 I'd like to create a dynamic thumbnail resizer so that you can use the following URL to get a resized image: http://server/images/image.jpg?width=320&height=240 I tried setting up a route like this: routes.MapRoute(null, "{filename}", new { controller = "Image", action = "Resize" }); But if the file exists at the URL, ASP.NET will bypass the routing and return you just the file instead. How do I force ASP.NET to route the images instead of returning what's on disk? 回答1: Thats how asp.net

Routing on IIS6 With Decimal In Route

混江龙づ霸主 提交于 2019-12-20 03:13:01
问题 I have a route in my MVC3 project that works perfectly fine locally when run through the debugger and through IIS7. However, our servers are IIS6 and when I move my application out I am getting a "The page cannot be found" error. My guess is it has to do with the decimal in the route.. So I have tried implementing a RouteHandler which seems to be getting called but is not working correctly because the value isn't overwritten in the route? Anyway, here is my route: var route = context.MapRoute

ASP.NET Core 2 default route having areas

北城余情 提交于 2019-12-18 17:26:26
问题 cI went through various posts regarding the Areas routing but still I am not able to resolve my issue. I would like to split my application in the way that there are two routes. /Areas/Panel /Areas/Website Inside each area there is HomeController and appropriate methods that correspond to actions. I would like that whenever user lands to any level 1 route i.e.: /home /contact /about/company etc. is directed to /Areas/Website/{controller}/{action} and alternatively for /panel /panel/home

ASP.NET route to mvc or api by subdomain

点点圈 提交于 2019-12-18 04:27:26
问题 Our application have 2 domains (www | api).mydomain.com How can I route requests to api.mydomain.com to api controllers and www to mvc controllers? Thank you 回答1: I solved my problem using constraints. This site gave me the clue: http://stephenwalther.com/archive/2008/08/07/asp-net-mvc-tip-30-create-custom-route-constraints.aspx And here is my implementation: public class SubdomainRouteConstraint : IRouteConstraint { private readonly string _subdomain; public SubdomainRouteConstraint(string

How to redirect to a dynamic login URL in ASP.NET MVC

有些话、适合烂在心里 提交于 2019-12-17 15:03:24
问题 I'm creating a multi-tenancy web site which hosts pages for clients. The first segment of the URL will be a string which identifies the client, defined in Global.asax using the following URL routing scheme: "{client}/{controller}/{action}/{id}" This works fine, with URLs such as /foo/Home/Index. However, when using the [Authorize] attribute, I want to redirect to a login page which also uses the same mapping scheme. So if the client is foo, the login page would be /foo/Account/Login instead

Is it possible to use System.Web.Routing in Castle Monorail?

a 夏天 提交于 2019-12-13 00:38:44
问题 Is it possible to use the Microsoft (or Mono) supplied System.Web.Routing instead of the MonoRail routing stuff when building a Castle MonoRail app for ASP.NET? Any good information on how to implement this as a solution? Pros and cons? 回答1: It is quite possible. You should implement ASP.NET's IRouteHandler that will look up the route data in the given RequestContext , and then hand the data over to MonoRail. That can be done is several ways. I guess that Server.RewritePath will work, but you

Redirecting route in ASP.NET WebAPI

耗尽温柔 提交于 2019-12-12 01:11:36
问题 This is ok: GlobalConfiguration.Configuration.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}", defaults: new { id = System.Web.Http.RouteParameter.Optional }); But I want to redirect incoming requests to ApiFolder folder's class 回答1: You should specify your namespace in your route configuration: var r = GlobalConfiguration.Configuration.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}", defaults: new { id = System.Web.Http