Getting full url of any file in ASP.Net MVC
new Uri(Request.Url, Url.Content(“~/images/image1.gif”))
new Uri(Request.Url, Url.Content(“~/images/image1.gif”))
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
I apologize in advance, this post strays a bit from what you asked, but all of this bubbled up when I read your question. WebAPI Matching Semantic The matching semantic used by (the default routes in) WebAPI is fairly simple. It matches the name of the action with the verb (verb = GET? look for … Read more
I added an instruction to my route config to ignore empty routes and that solved my problem. routes.IgnoreRoute(“”);
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
Try this: return RedirectToAction(“index”, “home”, new { area = “” });
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
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” } );
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″ />
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