asp.net-mvc-routing

Setting an alternate controller folder location in ASP.NET MVC

我与影子孤独终老i 提交于 2019-11-29 07:35:42
问题 We can an MVC app that uses the default folder conventions for the HTML views, but we'd like to set up alternate "Services" folder with controllers used only for web services returning xml or json. So the route "/Services/Tasks/List" would be routed to "/Services/TaskService.cs", while "/Tasks/List" would be routed to the standard "/Controllers/TaskController.cs" We'd like to keep the service controllers separate from the view controllers. We don't think areas or using another project will

How to have folder and controller with same name in ASP.NET MVC?

牧云@^-^@ 提交于 2019-11-29 06:14:59
I have a MVC controller called Downloads. http://mysite/Downloads I also want to put a physical file in a physical folder called http://mysite/Downloads/MyFile.zip . If I simply create a folder, I get a 403 when browsing to http://mysite/Downloads . (Most likely because of directory browsing is disabled) But I want the MVC controller to kick in instead. How do I do that? Daniel Elliott If you browse to http://mysite/Downloads/{ACTION} it will fire your controllers action. The only thing that won't work in your example is the /Downloads with no action. You could re-write this URL to redirect

ASP.NET MVC 4 Web API fails to map path containing the string “con”?

佐手、 提交于 2019-11-29 06:12:04
What is so wrong about the string "con"? OK, my api route configuration is rather uninteresting: config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); The LocationController has the following method: public List<LocationViewModel> Get(string id) { return _ds.SearchLocations(id); } Everything works as it should, except that I am getting an HTTP 404 error when I try to get the resource like this: /api/location/con In this case, the method is not hit. The strange thing is that if I set any other string other than

Possible Bug With ASP.NET MVC 3 Routing?

微笑、不失礼 提交于 2019-11-29 05:54:04
Normally i wouldn't put a title like this in the question, but i'm pretty sure it's a bug (or by design?) I created a brand new ASP.NET MVC 3 Web Application. Then i went to the /Home/About page. The URL for this page is: http://localhost:51419/Home/About Then i changed the URL to this: http://localhost:51419/(A(a))/Home/About And the page worked? Looking at the route values, controller = Home, Action = About. It's ignored the first part? And if i look at all the links in the source: <link href="/(A(a))/Content/Site.css" rel="stylesheet" type="text/css" /> <script src="/(A(a))/Scripts/jquery-1

Why CSS and JS files bypass Asp.Net MVC routes?

断了今生、忘了曾经 提交于 2019-11-29 05:12:28
问题 I received a prototype application built with Asp.Net MVC4. It is currently replacing the default controller factory with a custom one using NInject, ServiceLocator and all. The problem is that by replacing the default controller factory, the requests to JS files are being treated as if it was a legit request for a controller and an action. So, looking at the default template create by Visual Studio, route configuration looks like this: public static void RegisterRoutes(RouteCollection routes

Test if a request's URL is in the Route table

喜你入骨 提交于 2019-11-29 04:41:42
I want to test if a URL is part of the routes defined in the Global.asax . This is what I have: var TheRequest = HttpContext.Current.Request.Url.AbsolutePath.ToString(); var TheRoutes = System.Web.Routing.RouteTable.Routes; foreach (var TheRoute in TheRoutes) { if (TheRequest == TheRoute.Url) //problem here { RequestIsInRoutes = true; } } The problem is that I can’t extract the URL from the route. What do I need to change? The problem is that I can't extract the URL from the route. I disagree. The problem is that you expect to pull the URLs out of the route table and compare them externally.

url with extension not getting handled by routing

只谈情不闲聊 提交于 2019-11-29 03:35:33
I've been folowing the advice from this article for setting up a robots.txt file in asp.net mvc3 for using a controller to handle the server response, and IIS 8.0 express is returning a file not found error, rather than an asp.net error. How do I get IIS to not look for a file in these cases? Is there something I need in the web.config? Darin Dimitrov IIS tries to be intelligent here. He intercepts the dot in the url and thinks that this is a static file and attempts to serve it with the default StaticFile handler. it dopesn't event get to the managed ASP.NET application. The first possibility

asp.NET: Unknown length MVC paths

筅森魡賤 提交于 2019-11-29 02:39:41
I am building a MVC application in asp.NET for a web portal. I have prepared a series of controllers, and mapped all the paths that don't macth to this to a Page controller, which will render the appropriate page. My default route works like this: routes.MapRoute( "Default", "{level1}/{level2}/{level3}", new { controller = "Page", action = "Index", level1 = "home", level2 = "", level3 = "" } ); But this has fixed width, it will accept only up to 3 levels. Moreover, I'd like to manage actions appended to the path, like "edit" and "delete". Is this possible? company/about/who_we_are/staff ->

Pretty URL ASP.NET MVC

点点圈 提交于 2019-11-29 01:59:06
问题 How can I get pretty urls like localhost:8888/News/Example-post instead of localhost:8888/Home/Details/2 My HomeController has the following for the Details method public ActionResult Details(int id) { var ArticleToView = (from m in _db.ArticleSet where m.storyId == id select m).First(); return View(ArticleToView); 回答1: As the ASP.NET routing system is somewhat complicated, there are many ways to accomplish what you describe. First of all, do you just want to have a pretty URL for the Details

ASP.NET MVC Default URL View

◇◆丶佛笑我妖孽 提交于 2019-11-29 01:32:12
I'm trying to set the Default URL of my MVC application to a view within an area of my application. The area is called " Common ", the controller " Home " and the view " Index ". I've tried setting the defaultUrl in the forms section of web.config to " ~/Common/Home/Index " with no success. I've also tried mapping a new route in global.asax, thus: routes.MapRoute( "Area", "{area}/{controller}/{action}/{id}", new { area = "Common", controller = "Home", action = "Index", id = "" } ); Again, to no avail. George Stocker The route you listed only works if they explicitly type out the URL: yoursite