How can I create a route constraint of type System.Guid?

Create a RouteConstraint like the following: public class GuidConstraint : IRouteConstraint { public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) { if (values.ContainsKey(parameterName)) { string stringValue = values[parameterName] as string; if (!string.IsNullOrEmpty(stringValue)) { Guid guidValue; return Guid.TryParse(stringValue, out guidValue) && (guidValue != Guid.Empty); } } return false; }} Next when adding … Read more

How do I configure ASP.NET MVC routing to hide the controller name on a “home” page?

Try this: private void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”); routes.MapRoute(“default”, “{controller}/{action}/{id}”, new { action = “index”, id = “” }, // Register below the name of all the other controllers new { controller = @”^(account|support)$” }); routes.MapRoute(“home”, “{action}”, new { controller = “device”, action = “index” }); } e.g. /foo If foo is not a controller … Read more

asp.net mvc complex routing for tree path

You can create a custom route handler to do this. The actual route is a catch-all: routes.MapRoute( “Tree”, “Tree/{*path}”, new { controller = “Tree”, action = “Index” }) .RouteHandler = new TreeRouteHandler(); The tree handler looks at path, extracts the last part as action, and then redirects to the controller. The action part is also … Read more

ASP.net MVC4 WebApi route with file-name in it

You could add the following handler to the <handlers> section of your <system.webServer>: <add name=”ManagedDllExtension” path=”api/nav/*/*.dll” verb=”GET” type=”System.Web.Handlers.TransferRequestHandler” preCondition=”integratedMode,runtimeVersionv4.0″ /> This will make all requests containing .dll be served through the managed pipeline. Also notice how I have limited them only to the GET verb to limit the performance impact.

mvc Html.BeginForm different URL schema

A form with FormMethod.Get will always post back the values of its form controls as query string values. A browser cannot generate a url based on your route configurations because they are server side code. If you really wanted to generate /Stations/View/f2cecc62-7c8c-498d-b6b6-60d48a862c1c, then you could use javascript/jquery to build your own url and redirect @using … Read more

How to change route to username after logged in?

You need to add a route to cover the case that has a user name. public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”); routes.MapRoute( name: “Username_Default”, url: “{username}/{controller}/{action}/{id}”, defaults: new { controller = “Home”, action = “Index”, id = UrlParameter.Optional }, constraints: new { username = new OwinUsernameConstraint() } ); routes.MapRoute( name: “Default”, url: “{controller}/{action}/{id}”, defaults: … Read more

How to use an Area in ASP.NET Core

In order to include an Area in an ASP.NET Core app, first we need to include a conventional route in the Startup.cs file (It’s best to place it before any non-area route): In Startup.cs/Configure method: app.UseMvc(routes => { routes.MapRoute(“areaRoute”, “{area:exists}/{controller=Admin}/{action=Index}/{id?}”); routes.MapRoute( name: “default”, template: “{controller=Home}/{action=Index}/{id?}”); }); Then make a folder named Areas in the app … Read more

How to get RouteData by URL?

I used Moq to determine what members of HttpContextBase are used in GetRouteData(). They are: Request AppRelativeCurrentExecutionFilePath PathInfo Request.AppRelativeCurrentExecutionFilePath should return path with ~, what I exactly need, so utility class may be like this one: public static class RouteUtils { public static RouteData GetRouteDataByUrl(string url) { return RouteTable.Routes.GetRouteData(new RewritedHttpContextBase(url)); } private class RewritedHttpContextBase : … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)