asp.net-mvc-routing

Failing ASP.NET MVC route. Is this a bug or corner case?

梦想的初衷 提交于 2019-12-03 05:11:23
问题 I have an ASP.NET MVC 3 application where users can post suggestions along the lines of "bla bla would be better if yada yada yada". For the suggestion detail page I have defined a nice SEO friendly route as follows: routes.MapRoute(null, "suggestion/{id}/{it}/would-be-better-if-{if}", new { controller = "suggestion", action = "details" }); As you can see I want the "would be better if" part to be fixed. This route works perfectly for any old suggestion and generates links like suggestion/5

ASP.NET MVC Areas with shared layout

感情迁移 提交于 2019-12-03 04:43:40
问题 I have defined an area (Admin) in my ASP.NET MVC 3 application, created _ViewStart.cshtml in that area and added Layout = "~/Views/Shared/_Layout.cshtml"; to it to have a unified site layout. I also added the following code to _Layout.cshtml : if (HttpContext.Current.User.IsInRole("Admin")) { <li>@Html.ActionLink("Items List", "Index", "Items", new { area = "Admin" }, null)</li> } The Admin area is displayed properly having _Layout.cshtml as its layout. But all the navigation links in the

Difference between Url.RouteUrl() & Url.Action() in MVC3

本秂侑毒 提交于 2019-12-03 04:25:25
I am in the process of generating a URL dynamically in my cshtml page. What is the difference between Url.RouteUrl() & Url.Action()? Which one should I use to generate the URL & what difference do both have in terms of implementation ? Thanks in advance. RouteUrl generated the url based on route name. If you have multiple routes with similar parameters the Action method may pick a wrong one - it works based on the order of route definitions. This may take place when your routes have optional parameters. If you want to make sure that a certain route url will be used you need to call RouteUrl

Routing in Web Api in ASP.NET MVC 4

孤街浪徒 提交于 2019-12-03 04:10:57
I am using web api with ASP.NET MVC 4. I have the following named controller CustomerController : Controller CustomerApiController : ApiController Earlier my CustomerApiController was named CustomersController so to access it, I simply had to punch in the following url localhost/api/Customers but now I have to keep the api controller name as CustomerApiController . I want to be able to hit the same method using localhost/api/Customers what changes do I have to make ? I have tried making some changes in the RouteConfig.cs file. I tried adding the following to the RegisterRoutes method, but none

Customizing ASP.NET MVC Routing to service “.json” “.xml” Style Urls

爷,独闯天下 提交于 2019-12-03 02:59:07
I have a search Api I'm working on that needs to return search results in a block of Html (using styles the client has defined on their end). I would also like to return results in Json, for future Api stuff we'll eventually be using. Currently, the routes look like this: /api/1/search/json?param1=blah&param2=blah&etc /api/1/search/html?param1=blah&param2=blah&etc For reference, the pattern here is /{area}/1/{controller}/{action}. I like the look of some Api's I've seen that return results in different formats depending on the 'extension' they have in the url, a la: /api/1/search.json?param1

Is it possible to use different layouts in MVC4 based off of routes?

ぐ巨炮叔叔 提交于 2019-12-03 01:38:41
I have a separate section (route) of my website that I would like to use a different layout/css etc. So when users at the main section of my website they get the default layout. But when they log in and go to the store, the store section (route) uses a different layout/css. So... www.blahblahblah.com/ www.blahblahblah.com/admin/ www.blahblahblah.com/home/contactus/ ...all use the default _Layout BUT... www.blahblahblah.com/store/ www.blahblahblah.com/store/admin/ ...use _LayoutStore I've seen this done based off of roles here ( http://forums.asp.net/t/1653362.aspx/1 ) and here ( How to use

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

安稳与你 提交于 2019-12-03 01:10:34
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? if you don't want to use RedirectToAction (for me is the right choice) you can use return Redirect(Url.Content("~/")); UPDATE As stated

How to make more MapHttpRoutes for MVC 4 Api

喜欢而已 提交于 2019-12-02 23:08:14
I have 2 API routes for my API atm, but I want to add more, and the way I am doing it it seems to overwrite each other, so in the code I pasted, only the CreateUser route works. public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapHttpRoute( name: "CreateUser", routeTemplate: "api/{controller}/{cUser}", defaults: new { controller = "User", action = "CreateUser", cUser = RouteParameter.Optional }); routes.MapHttpRoute( name: "AllGames", routeTemplate: "api/{controller}/{playerId}", defaults: new { controller = "Game", action =

ASP MVC 5 Attribute routing VS. Convention-based routing

此生再无相见时 提交于 2019-12-02 22:35:51
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 maintainability and readibility. To address your first question, scattering the routes has a number of advantages:

Can Areas in an ASP.NET MVC 2 application map to a subdomain?

做~自己de王妃 提交于 2019-12-02 22:28:39
Is there a way to map the Areas within an ASP.NET MVC 2 application to subdomains such as movies.example.com/Theater/View/2 instead of example.com/Movies/Theater/View/2 where { area = "Movies", controller = "Theater", action = "View", id = 2 }. Eilon Areas are not directly related to routing, so your question becomes "does routing support subdomains?" The answer to that is unfortunately that there is no built-in support for this. However, the good news is that many people have tried and found success with custom code that builds on top of routing: Is it possible to make an ASP.NET MVC route