asp.net-mvc-routing

Virtual Directory App within a Asp.net MVC app

廉价感情. 提交于 2019-12-07 14:26:04
问题 I am having issues trying to host screwturn wiki as a virtual directory application within my current domain. the domain is hosted as something.com and the wiki would look like something.com/wiki when i browse to something.com/wiki I get Could not load file or assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. Why is the virtual directory falling back to the root application.

ASP.NET Catch all routing and escaping forward slashes

南笙酒味 提交于 2019-12-07 13:57:54
问题 I'm using catch-all routing with MVC to provide a path to a resource in our application. It looks like such: _routes.MapRoute(null, "Resource/{*resourcePath}", new { controller = "Resource", action = "Open" }); And the action is something like public ActionResult Open(string resourcePath) { string[] path = resourcePath.Split('/'); } Hitting it with a nice and friendly URL it works fine /Resource/Path/To/Resource path = ["Path", "To", "Resource"] But when I have a resource name with a forward

MVC Custom Route. DataTokens[“Namespaces”] is ignored

点点圈 提交于 2019-12-07 12:27:17
问题 I don't know why while creating a CustomRoute which inherits from Route , the field DataTokens["Namespaces"] is ignored. And I get the error: Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter. Here is

Route value with dashes

强颜欢笑 提交于 2019-12-07 11:34:27
问题 I have this route: routes.MapRoute( "News", "News/{id}-{alias}", new { controller = "News", action = "Show" }, new { id = @"^[0-9]+$" }, namespaces: new[] { "Site.Controllers" } ); This route working for url's like this: http://localhost:54010/News/6-news But not working for url's like this: http://localhost:54010/News/6-nice-news How use dashes in my route value "alias"? EDITED Route like this: "News/{id}_{alias}" works for both url's: http://localhost:54010/News/6_news http://localhost

ASP.NET MVC: Uri to usable route data

╄→尐↘猪︶ㄣ 提交于 2019-12-07 11:28:48
问题 My problem is pretty simple. I've got a Uri and I want to figure out which route it maps to so I can do some checks on the various pieces of the route: controller, action, etc. How do I go from Uri to RouteData or Route? 回答1: Based on @tvanfosson's direction, I came up with a class that does what I need. Note that the GetRouteData actually looks at the AppRelativeCurrentExecutionFilePath and the PathInfo properties on the RequestContextBase class, not the Url property. public class RouteInfo

Problems with creating two routes which won't generate 404 error in ASP.NET MVC

China☆狼群 提交于 2019-12-07 11:20:19
问题 I'm trying to build my tutorial project with routing. My main objective is to build two routes which won't generate 404 error in any case. By this I mean that if the path is wrong I want routing to use /Home/Index path. I have two following routes - routes.MapRoute("Default", "{controller}/{action}", new {controller = "Home", action = "Index"} ); routes.MapRoute("Second", "{*catchall}", new {controller = "Home", action = "Index", id = UrlParameter.Optional} ); It works fine when I use

Default-Route for root of application

我怕爱的太早我们不能终老 提交于 2019-12-07 11:17:46
问题 How can I tell my mvc -application to route to a specific Controller and Action when they are not specified? When debugging http://localhost:54500/ should route to http://localhost:54500/Home/Index . Currently I have: routes.MapRoute( name: "Root", url: "", defaults: new { controller = "Home", action = "Index" } ); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { id = UrlParameter.Optional } ); But this always throws The view 'Index' or its master was not

Register routes in area registration

心已入冬 提交于 2019-12-07 06:56:26
问题 I have two routes in my area, one custom and one default fallback route, see below var dashboardRoute = new DashboardRoute( ObjectFactory.GetInstance<PathResolver>(), ObjectFactory.GetInstance<VirtualPathResolver>(), null); context.Routes.Add(dashboardRoute); context.Routes.MapRoute( "Dashboard_Default", // Route name "dashboard/{controller}/{action}/{id}", // URL with parameters new { controller = "pages", action = "index", id = UrlParameter.Optional, area = "Dashboard" } // Parameter

Permanent Redirect Legacy Routes for static files in ASP.Net MVC

我只是一个虾纸丫 提交于 2019-12-07 04:48:10
问题 Our old ASP.net site stored static images in a sub directory on the root called /images . Our new ASP.net MVC site stores these images in the new layout of /Content/Images I've changed all the pages in the site to cope with the new folder structure, but I'd like to set up Permanent Redirects from the old static images to the new location. Our site is hosted, and I don't have control over IIS, so what is the best approach to solve this? 回答1: I use the following code for my MVC 2 websites: //

Mixing ASP.NET MVC into ASP.NET WebForms

Deadly 提交于 2019-12-07 04:38:09
问题 For some reason my routing is ignoring any attempt to access my MVC pages and simply giving me 404s. I have a WebForms app set up like the following: Virtual Directory: thing So I usually access my site like so: http://localhost/thing/someFile.aspx http://localhost/thing/someFolder/anotherFile.aspx The original stucture of my ASP.NET WebForms app mirrors the file system so I have folders full of .aspx files and I need to be able to use them like that. For some reason when I try to access a