asp.net-mvc-routing

ASP.NET MVC Route with values before the controller and no trailing slash

两盒软妹~` 提交于 2019-11-27 07:59:16
问题 This is probably a simple question but I just can't get it to work. I've got this route specified in my RouteConfig routes.MapRoute( name: "DefaultSiteRoute", url: "{accountid}/{hostname}/{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, accountid = UrlParameter.Optional, hostname = UrlParameter.Optional } ); And it works fine for a url like this /123456/www.test.com/ or this /123456/www.test.com/Controller/Action but it can't cope

How to make ASP.NET Routing escape route values?

风流意气都作罢 提交于 2019-11-27 07:50:50
问题 I have an ASP.NET MVC site where I want routes like /{controller}/{id}/{action}/{date} , where "date" is the mm/dd/yyyy portion of a date/time. (I'm dealing with time-dimensioned data, so I need both an ID and a point in time to do most operations) The route for this is simple: routes.MapRoute( "TimeDimensionedRoute", "{controller}/{id}/{action}/{date}", new { controller = "Iteration", action = "Index", id = String.Empty, date = String.Empty } ); This route correctly maps " /Foo/100/Edit/01

HTTP Error 403.14 - Forbidden - MVC 4 with IIS Express

本小妞迷上赌 提交于 2019-11-27 07:35:32
问题 This seems like a question that has already been asked/answered many times. Its not. Development Environment: VS 2012 and MVC 4. I am using the built in IIS Express to run the app. This error was not occurring until yesterday. It suddenly began to occur and I am stuck. Its strange that It occurs only in ONE scenario. When I try to access http://localhost:49962/managescholars/ , it shows me the error HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this

How can I create a route constraint of type System.Guid?

杀马特。学长 韩版系。学妹 提交于 2019-11-27 07:33:37
Can anyone point me in the right direction on how to map a route which requires two guids? ie. http://blah.com/somecontroller/someaction/ {firstGuid}/{secondGuid} where both firstGuid and secondGuid are not optional and must be of type system.Guid? Create a RouteConstraint like the following: public class GuidConstraint : IRouteConstraint { public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) { if (values.ContainsKey(parameterName)) { string stringValue = values[parameterName] as string; if (!string

How to achieve a dynamic controller and action method in ASP.NET MVC?

血红的双手。 提交于 2019-11-27 06:59:29
In Asp.net MVC the url structure goes like http://example.com/ {controller}/{action}/{id} For each "controller", say http://example.com/blog , there is a BlogController. But my {controller} portion of the url is not decided pre-hand, but it is dynamically determined at run time, how do I create a "dynamic controller" that maps anything to the same controller which then based on the value and determines what to do? Same thing with {action}, if the {action} portion of my url is also dynamic, is there a way to program this scenario? Ryan Absolutely! You'll need to override the

jQuery Mobile/MVC: Getting the browser URL to change with RedirectToAction

喜夏-厌秋 提交于 2019-11-27 06:59:00
My first post... When I use RedirectToAction the url in the browser doesn't change. How can I achieve this? I'm switching over to ASP.NET MVC 3.0 (also using jQuery Mobile) after 10+ years using web forms. I'm about 8 weeks into it, and after several books and scouring Google for an answer, I'm coming up dry. I have a single route defined in Global.asax: routes.MapRoute( "Routes", "{controller}/{action}/{id}", new { controller = "Shopping", action = "Index", id = UrlParameter.Optional } I have a ShoppingController with these actions: public ActionResult Cart() {...} public ActionResult

Set “Homepage” in Asp.Net MVC

血红的双手。 提交于 2019-11-27 06:56:27
In asp.net MVC the "homepage" (ie the route that displays when hitting www.foo.com) is set to Home/Index . Where is this value stored? How can I change the "homepage"? Is there anything more elegant than using RedirectToRoute() in the Index action of the home controller? I tried grepping for Home/Index in my project and couldn't find a reference, nor could I see anything in IIS (6). I looked at the default.aspx page in the root, but that didn't seem to do anything relevent. Thanks Michael Stum Look at the Default.aspx/Default.aspx.cs and the Global.asax.cs You can set up a default route:

How can I get controller type and action info from a url or from route data?

亡梦爱人 提交于 2019-11-27 06:49:45
问题 How can I get the controller action (method) and controller type that will be called, given the System.Web.Routing.RouteData ? My scenario is this - I want to be able to do perform certain actions (or not) in the OnActionExecuting method for an action. However, I will often want to know not the current action, but the "root" action being called; by this I mean I may have a view called "Login", which is my login page. This view may include another partial view "LeftNav". When OnActionExecuting

How to use an Area in ASP.NET Core

时光总嘲笑我的痴心妄想 提交于 2019-11-27 06:48:16
How do I use an Area in ASP.NET Core? I have an app that needs an Admin section. This section requires its Views to be placed in that area. All requests that start with Admin/ will need to be redirected to that area. Vahid Amiri In order to include an Area in an ASP.NET Core app, first we need to include a conventional route in the Startup.cs file (It's best to place it before any non-area route): In Startup.cs/Configure method: app.UseMvc(routes => { routes.MapRoute("areaRoute", "{area:exists}/{controller=Admin}/{action=Index}/{id?}"); routes.MapRoute( name: "default", template: "{controller

Ensure that HttpConfiguration.EnsureInitialized()

做~自己de王妃 提交于 2019-11-27 06:30:58
I've installed Visual Studio 2013 and when I run my app I get the error below. I've got no idea as to where I'm to initialized this object. What to do? Server Error in '/' Application. The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is called in the application's startup code after all other initialization code. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System