asp.net-mvc-routing

ASP.NET MVC Url.Action and route name value

徘徊边缘 提交于 2019-12-03 11:36:19
问题 I am using asp.net mvc 2 and create localization based on routes. my route looks like: {culture}/{controller}/{action} I go to my home controller: en/Home/Index my home controller view have a links to other controllers: <a href='<%= Url.Action("Prods","Products") %>' >Products</a> <a href='<%= Url.Action("Index","About") %>' >About</a> First link generated code: /en/Products/Prods but second one generate: /Home/Index I can't understand why Url.Action skips the {culture} route parameter when I

How can I redirect my action to the root of the web site?

爷,独闯天下 提交于 2019-12-03 10:42:41
问题 I have the following code in my controller to redirect my user after he has logged out: public ActionResult Logout() { FormsAuthentication.SignOut(); return new RedirectToRouteResult( new RouteValueDictionary( new { area = "Administration", controller = "Menus", action = "Home" } ) ); } I would like to redirect the user to / or the base URL (root) of my site. Is there a way that I can do this without having to give details of the area, controller and action? 回答1: if you don't want to use

What is Routedata.Values[“”]?

假装没事ソ 提交于 2019-12-03 10:19:06
I am surprised to see that there is no article which answers this question with any details. I have few questions related to RouteData.Values[""] . I saw this code: public ActionResult Index() { ViewBag.Message = string.Format("{0}---{1}--{2}", RouteData.Values["Controller"], RouteData.Values["action"], RouteData.Values["id"]); return View(); } Here it is basically reading values which potentially sounds like "Meta-data" of the controller. Or is it something that View can also pass to Controller? RouteData.Values is used for accessing the values/querystring values inserted by the classes

ASP MVC 5 Attribute routing VS. Convention-based routing

扶醉桌前 提交于 2019-12-03 09:36:19
问题 ASP MVC 5 has a new Routing called attribute routing. The way I see it, the routes are now scattered on every controller unlike with the convention-based that there is single location RouteConfig.cs where you can check your routes, which also serves as documentation of your sites routes in some way. My question is it better to use Attribute routing over the convention-based routing in terms of readability and maintainability? And can someone suggest how to design routes for better

asp.net mvc. Routing and Url building

无人久伴 提交于 2019-12-03 09:00:24
Does any body knows how to hide some parameters in url? For example you have a url parameter "culture". It can be "en, fr, it". By default your site renders in "en" culture and we don't wont to show default culture in the URL but in cases of other cultures parameter "culture" must appear in URL. http://myrendersite.net/barbikueue http://myrendersite.net/fr/barbikueue This is same pages in different cultures. How to do what basing on default asp.net mvc routing system? Cristi Pufu This will help: ASP.NET mvc, localized routes and the default language for the user asp.net mvc localization Set

Remove Trailing Slash in ASP.NET MVC 4 Route to Application Root

别说谁变了你拦得住时间么 提交于 2019-12-03 08:55:19
In my ASP.NET MVC 4 application's RouteConfig file, I have registered the following default route: routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "home", action = "index", id = UrlParameter.Optional }); Now, in my Razor views, I want to generate a URL to my application's root like that: <a href="@Url.Action("index", "home")">Home</a> The generated URL includes a trailing slash; clicking the link thus opens the page localhost/IISApplicationName /. However, I want the URL not to contain the trailing slash so that the URL is localhost/IISApplicationName . Generating

Setting up ASP.Net MVC 4 Routing with custom segment variables

南楼画角 提交于 2019-12-03 08:36:36
I just began working on an application with a couple areas (basic grid master / details type system..) I'm looking into taking advantage of the nice routing features in MVC (4 specifically) and I'm "just not getting it" I presume. Currently the only route defined is the basic one: routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Account", action = "Index", id = UrlParameter.Optional } ); which is fine, it works with the areas we have defined, so I'm assuming it must know where the user is and route to the appropriate controller based contextually on the location /

How can I combine a MVC4 site and a WebAPI site under the same IIS website?

↘锁芯ラ 提交于 2019-12-03 08:34:29
I have a project (named Product.Api ) that has some controllers used for our WebAPI site. The controllers are in a namespace Product.Api.Controllers . The project also has some other helper stuff as well. This is compiled into a library. I also have another regular ASP.NET MVC4 website named Product.Web . This has Controllers (under the namespace Product.Web.Controllers ), Models and Views (in its corresponding folders). It also has a Global.asax.cs which has the routing information. When the site is created in IIS (.NET 4.5, IIS7, integrated mode, etc), I copy the Product.Api dll into the bin

ASP.NET MVC 3: Moved app into virtual directory. What do I have to change?

放肆的年华 提交于 2019-12-03 07:23:12
Folks, I have been working on an MVC 3 app. I was using VS 2010's built-in web server. Today, for various reasons, I was asked to move it into a virtual directory and run it under IIS 7, still on my development PC. Now that its URL is "localhost/MyVirtualDirectory" as opposed to "localhost:12345", what do I need to change to make routing work, and where? I'm not using any raw HTML anchor tags or redirects, just @Html.ActionLink and so on. According to what I've read, if I've been doing things the MVC way, this change should have been transparent. But right at the beginning, the post

ASP.NET MVC URL generation performance

邮差的信 提交于 2019-12-03 07:12:15
问题 A little benchmark with ASP.NET MVC. Viewpage code: public string Bechmark(Func<string> url) { var s = new Stopwatch(); var n = 1000; s.Reset(); s.Start(); for (int i = 0; i < n; i++) { var u = url(); } s.Stop(); return s.ElapsedMilliseconds + " ms, " + ((s.ElapsedMilliseconds) / (float)n) + " ms per link<br/>"; } View code: <%= Bechmark(() => Url.Action("Login", "Account")) %> <%= Bechmark(() => Url.Action("Login", "Account", new {username="bla", password="bla2", returnurl="blabla32",