How to prevent Url.RouteUrl(…) from inheriting route values from the current request

My solution was this : An HtmlExtension helper method : public static string RouteUrl(this UrlHelper urlHelper, string routeName, object routeValues, bool inheritRouteParams) { if (inheritRouteParams) { // call standard method return urlHelper.RouteUrl(routeName, routeValues); } else { // replace urlhelper with a new one that has no inherited route data urlHelper = new UrlHelper(new RequestContext(urlHelper.RequestContext.HttpContext, new … Read more

ASP.NET MVC custom routing for search

Option 1 Of course you always can choose the way of /car/search/?vendor=Toyota&color=Red&model=Corola and I think it will be good for you. routes.MapRoute( “CarSearch”, “car/search”, new { controller = “car”, action = “search” } ); You can get params from Request.Params in action in this case. Option 2 Or you can define params in the routing … Read more

How do I set the default namespaces in MapHttpRoute?

We had this problem with the Umbraco core so we created our own IHttpControllerSelector, the source code can be found here: https://github.com/WebApiContrib/WebAPIContrib/blob/master/src/WebApiContrib/Selectors/NamespaceHttpControllerSelector.cs You can also install nuget package WebAPIContrib which contains NamespaceHttpControllerSelector. To register this you can do this on app startup: GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerSelector), new NamespaceHttpControllerSelector(GlobalConfiguration.Configuration)); The implementation is pretty straight forward and only deals with … Read more

ASP.NET MVC 4 – 301 Redirects in RouteConfig.cs

You have to use RedirectPermanent, here’s an example: public class RedirectController : Controller { public ActionResult News() { // your code return RedirectPermanent(“/News”); } } in the global asax: routes.MapRoute( name: “News old route”, url: “web/news/Default.aspx”, defaults: new { controller = “Redirect”, action = “News” } );

ASP.NET MVC – Routing – an action with file extension

You need to map requests for your XML files to TransferRequestHandler in web.config. Otherwise IIS will handle the request. Jon Galloway explains how to do this here. In summary, you add this element to location/system.webServer/handlers in your web.config: <add name=”XmlFileHandler” path=”*.xml” verb=”GET” type=”System.Web.Handlers.TransferRequestHandler” preCondition=”integratedMode,runtimeVersionv4.0″ />

Routing in Asp.net Mvc 4 and Web Api

You could have a couple of routes: public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: “ApiById”, routeTemplate: “api/{controller}/{id}”, defaults: new { id = RouteParameter.Optional }, constraints: new { id = @”^[0-9]+$” } ); config.Routes.MapHttpRoute( name: “ApiByName”, routeTemplate: “api/{controller}/{action}/{name}”, defaults: null, constraints: new { name = @”^[a-z]+$” } ); config.Routes.MapHttpRoute( name: … Read more

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