asp.net-mvc-routing

how to remove the controller name from the url using rout in MVC [duplicate]

前提是你 提交于 2019-11-28 06:41:41
问题 This question already has an answer here: ASP.NET MVC - Removing controller name from URL 5 answers How to remove the controller name from the URL in MVC 5. I tried to add the route in the route.config public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapMvcAttributeRoutes(); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id

Asp.Net Custom Routing and custom routing and add category before controller

老子叫甜甜 提交于 2019-11-28 06:25:05
问题 I'm just learning MVC and want to add some custom routing to my site. My site is split into brands so before accessing other parts of the site the user will select a brand. Rather than storing the chosen brand somewhere or passing it as a parameter I would like to make it part of the URL so to access the NewsControllers index action for example rather than "mysite.com/news" I would like to use "mysite.com/brand/news/" . I just really want to add a route which says if a URL has a brand, go to

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

回眸只為那壹抹淺笑 提交于 2019-11-28 04:54:48
How can I add a route to the RouteConfig.cs file in an ASP.NET MVC 4 app to perform a permanent 301 redirect to another route? I would like certain different routes to point at the same controller action - it seems a 301 would be best practice for this, specially for SEO? Thanks. 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",

Considerations when turning on RouteExistingFiles

喜你入骨 提交于 2019-11-28 04:33:42
问题 I am looking to generate some CSS files dynamically in my Content folder. At the moment, this folder has an ignore route ( routes.IgnoreRoute("Content/{*wildcard}"); ) and, I'd like that to remain, as I don't need/want most of my content folders to go into the MVC request lifecycle. Example: routes.MapRoute( "DynamicCSS", "Content/Css/Dynamic/{guid}.css", new { controller = "Site", action = "GenerateCSS" }, new { guid = @"^([0-9a-fA-F]){8}([0-9a-fA-F]){4}([0-9a-fA-F]){4}([0-9a-fA-F]){4}([0-9a

Return either xml or json from MVC web api based on request

流过昼夜 提交于 2019-11-28 04:32:27
Given the following webapiconfig; config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); and this controller; public class ProductsController : ApiController { Product[] _products = new Product[] { new Product { Id = 1, Name = "Tomato Soup", Category = "Groceries", Price = 1 }, new Product { Id = 2, Name = "Yo-yo", Category = "Toys", Price = 3.75M }, new Product { Id = 3, Name = "Hammer", Category = "Hardware", Price = 16.99M } }; public IEnumerable<Product> GetAllProducts() { return _products; } } Using the URL

How do I use Server.Transfer method in asp.net MVC?

拟墨画扇 提交于 2019-11-28 04:25:59
问题 I am trying to use it for Login page. if (Session["UserID"] == null) Server.Transfer("/Account/Login", true); But I get The Exception -> Error executing child request /Account/Login. 回答1: To use a server transfer method you could look at this from Simon Weaver, but in the context of your question I would use a redirect action instead. RedirectToAction(new { controller="Account", action="Login" }); to get it to tell the login controller where to go back to try RedirectToAction( new {

How am I supposed to use ReturnUrl = ViewBag.ReturnUrl in MVC 4

冷暖自知 提交于 2019-11-28 04:07:04
I'm working on 'ASP.NET MVC 4' application. I'm using/learning SimpleMembershipProvider and try to stick to the default logic created by VS2012 with the Internet template (if I'm not mistaken, the one with 'SimpleMembershipProvider' out of the box). I'm stuck at the AccountController where I just can't figure put how exactly I can use this method: private ActionResult RedirectToLocal(string returnUrl) { if (Url.IsLocalUrl(returnUrl)) { return Redirect(returnUrl); } else { return RedirectToAction("Index", "Home"); } } From what I understand the whole idea is to get redirected to the location

Dot character in ASP.NET MVC 3 route parameters

前提是你 提交于 2019-11-28 02:01:28
问题 I have no custom routes in my application, only the default one. If i try to open localhost/myapp/controller/action/bla.bla it works fine on my machine (Windows 7 x32, both Cassini and IIS) but fails on the server (2008 R2 x64). Found similar question but the solution doesn't work. Also, found this article where Eilon says it's a special character for MVC and it's "by design". Why there is difference between my machine and the production box and how do i fix it? Update : the problem site has

ASP.Net MVC3 routing reserved words?

核能气质少年 提交于 2019-11-28 01:53:00
I have an ASP.Net MVC application with the standard routes defined. The app edits meta data for our database. The url scheme is: http://localhost/tables/Edit/[Name of Table Here] This calls the edit function on the tables controller and passes in the name of the table as the parameter id . All of the tables work fine except one named con . The following URL results in a 404: http://localhost/tables/Edit/con The only thing I can think of is that con must be some sort of reserved word with respect to MVC routing. Does anyone know whether this is the case and if there are other reserved words to

AngularJs routing with Asp.Net Mvc

烈酒焚心 提交于 2019-11-28 01:49:27
问题 I'm trying to build a SPA with Asp.Net MVC. for this I'm using angularJs routing . This is my project hierarchy. My Layout.cshtl code <html lang="en" ng-app="ProjectTrackingModule"> <head> <script src="~/Scripts/jquery-2.1.0.min.js"></script> <script src="~/Scripts/angular.min.js"></script> <script src="~/Scripts/angular-route.min.js"></script> <script src="~/Scripts/app.js"></script> </head> <body> <a href="#Home">Home</a> <a href="#Projects">Projects</a> <div ng‐view style="margin‐left: 10%