asp.net-routing

ready to use uint route constraint?

a 夏天 提交于 2020-06-16 18:37:14
问题 I have a .NET Core Web API project and my Ids are integers starting at 1. In most samples I see something like this [HttpGet("{id:int}")] public async Task<ActionResult<User>> GetUserByIdAsync([FromRoute] int id) { // ... } Since I know Ids must be greater than 0 I also added the :min(1) route constraint. But wouldn't it be better to change the integer datatype to uint ? The route would then be "{id:uint:min(1)}" and the method parameter will change to [FromRoute] uint id but unfortunately

ready to use uint route constraint?

陌路散爱 提交于 2020-06-16 18:35:24
问题 I have a .NET Core Web API project and my Ids are integers starting at 1. In most samples I see something like this [HttpGet("{id:int}")] public async Task<ActionResult<User>> GetUserByIdAsync([FromRoute] int id) { // ... } Since I know Ids must be greater than 0 I also added the :min(1) route constraint. But wouldn't it be better to change the integer datatype to uint ? The route would then be "{id:uint:min(1)}" and the method parameter will change to [FromRoute] uint id but unfortunately

Populate routetable of wcf from database

徘徊边缘 提交于 2020-01-24 20:59:48
问题 I want to add end points dynamically to routing table of wcf. Code: [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class PersonService : IPersonService { [WebInvoke(UriTemplate = "", Method = "GET")] public void GetPerson() { string k = "a"; } } [ServiceContract] public interface IPersonService { [OperationContract] void GetPerson(); } public class Global : System.Web.HttpApplication { protected void Application_Start(object sender,

Populate routetable of wcf from database

China☆狼群 提交于 2020-01-24 20:59:28
问题 I want to add end points dynamically to routing table of wcf. Code: [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class PersonService : IPersonService { [WebInvoke(UriTemplate = "", Method = "GET")] public void GetPerson() { string k = "a"; } } [ServiceContract] public interface IPersonService { [OperationContract] void GetPerson(); } public class Global : System.Web.HttpApplication { protected void Application_Start(object sender,

Why is this route parameter tacked onto the querystring?

我是研究僧i 提交于 2020-01-24 03:56:04
问题 I have an ASP.NET MVC 3 application that records a user's pedometer entries. A user can view all most recent pedometer entries by visiting /Pedometer and can filter by year, year/month, or year/month/date by visiting URLs like /Pedometer/2011 , /Pedometer/2011/08 and /Pedometer/2011/08/15 , respectively. I've created two mapped routes in Global.asax . The first route, shown below, is what allows the various URL patterns for filtering by date. The second route (not shown) is the default ASP

Advanced ASP.NET MVC routing scenario

邮差的信 提交于 2020-01-16 08:35:23
问题 I have an ASP.NET MVC app with the following deployment requirements: The URL structure must be something like: http://server/app/[enterprise]/[communinty]/{controller}/{action}/... What I think I want to be able to do is intercept the URL before the MVC route handler gets its hands on it, remove the [enterprise]/[community] parts, and then allow MVC to continue processing as if the original URL had not contained those two segments. Here's why: The application exposes multiple portals to

MapPageRoute - can't send empty strings in the middle?

て烟熏妆下的殇ゞ 提交于 2019-12-24 19:36:01
问题 In Global.asax.cs in a project that I'm maintaining there is a method that looks like this private static void MapRouteWithName(string name, string url, string physicalPath, bool? checkPhysicalUrlAccess = null, RouteValueDictionary defaults = null) { Route route; if ((checkPhysicalUrlAccess != null) && (defaults != null)) { route = System.Web.Routing.RouteTable.Routes.MapPageRoute(name, url, physicalPath, checkPhysicalUrlAccess.Value, defaults); } else { route = System.Web.Routing.RouteTable

Passing in a querystring with a space?

无人久伴 提交于 2019-12-24 08:16:53
问题 I have an action like this: public ActionResult UserDetails(string id) { } context.MapRoute( "Admin_Default", "{controller}/{action}/{id}", new { action = "Index", controller = "Start", id = UrlParameter.Optional } ); In another view i have a list with users from the standard membership management in .net Idea is that you click on a username to show the details and this works, only if the username is in one word. I recently encountered a username that looks like this: Steven C.H. Andersson So

Make ASP.NET MVC Route Id parameter required

僤鯓⒐⒋嵵緔 提交于 2019-12-22 09:41:02
问题 I have this route: routes.MapRoute( "PlaceDetails", "{controller}/{action}/{id}", new { controller = "Place", action = "Details", id = UrlParameter.Optional } ); This routes this fine: mysite.com/place/details/123 Making Id 123 available to the details action of the place controller - which can then lookup place '123'. However - this URL is also passed to the controller: mysite.com/place/details/ I want this to return HttpNotFound - but it sends a null Id to the controller - and requires me

ASP.NET MVC: Routing hierarchy URL

故事扮演 提交于 2019-12-22 09:03:03
问题 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