asp.net-mvc-routing

MVC 5 Routing Attribute

纵饮孤独 提交于 2019-11-30 23:23:53
问题 I have the Home Controller and my Action name is Index. In My route config the routes like below. routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); Now I call my page like http://localhost:11045/Home/Index is correct. If I call my page like following it should redirect to error page. localhost:11045/Home/Index/98 or localhost:11045/Home/Index/?id=98 .

Prevent static file handler from intercepting filename-like URL

与世无争的帅哥 提交于 2019-11-30 23:12:11
问题 In my web application I have a route which looks like this: routeCollection.MapRoute( "AdfsMetadata", // name "FederationMetadata/2007-06/FederationMetadata.xml", // url new { controller = "AdfsController", action = "MetaData" }); // defaults The idea behind this route was to work better with Microsoft AD FS server (2.0+) which looks for AD FS metadata at this point when you just specify a host name. With MVC3 all worked fine. But we upgraded the project to MVC4 recently and now the call for

Passing querystrings to RedirectToRouteResult (beside controller and action)

谁都会走 提交于 2019-11-30 22:12:29
问题 I have the following code: var routeDictionary = new RouteValueDictionary {{"action", "Login"}, {"controller", "Persons"}}; filterContext.Result = new RedirectToRouteResult(routeDictionary); That will produce " /Persons/Login " How can I pass an aditional querystring to the previous code? so that it produces " /Persons/Login/?someQuerystring=someValue " 回答1: Try this: filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary { { "action", "login" }, { "controller", "persons"

Set default action (instead of index) for controller in ASP.NET MVC 3

天大地大妈咪最大 提交于 2019-11-30 21:37:53
问题 I have a controller called Dashboard with 3 actions: Summary , Details , and Status , none of which take an ID or any other parameters. I want the URL /Dashboard to route to the Summary action of the Dashboard controller, as /Dashboard/Summary does, but I can't figure out the correct way to add the route. In Global.asax.cs , I have the following: routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new {controller = "Home", action = "Index", id =

ASP.NET Web API get child list (hierarchical resources)

纵然是瞬间 提交于 2019-11-30 21:34:28
I have the following rest schema that I'd like to implement using the ASP.NET Web Api: http://mydomain/api/students http://mydomain/api/students/s123 http://mydomain/api/students/s123/classes http://mydomain/api/students/s123/classes/c456 I've got the first two links working properly using the ApiController and the following two methods: public class StudentsController : ApiController { // GET api/students public IEnumerable<Student> GetStudents() { } // GET api/students/5 public IEnumerable<Student> GetStudent(string id) { } } In this same controller, (or do I need a different controller

Having trouble with a simple MVC route

你说的曾经没有我的故事 提交于 2019-11-30 19:03:56
问题 Having some trouble with some routes. I don't fully understand the MVC routing system so bear with me. I've got two controllers, Products and Home (with more to come!). I want to have the views within the Home controller accessible without having to type Home in the url. Essentially I want to turn www.example.com/home/about into www.example.com/about, however I still want to preserve the www.example.com/products. Here's what I have so far. routes.MapRoute( "Home", "{action}", new { controller

Switching to {controller}/{id}/{action} breaks RedirectToAction

孤街浪徒 提交于 2019-11-30 19:00:18
I am trying to use proper REST urls with MVC . To do that I switched default Routing from: {controller}/{action}/{id} to {controller}/{id}/{action} so instead of: /Customer/Approve/23 there is now /Customer/23/Approve ActionLink seems to work ok, but the following code in CustomerController: [CustomAuthorize] [HttpGet] public ActionResult Approve(int id) { _customerService.Approve(id); return RedirectToAction("Search"); //Goes to bad url } ends up on url /Customer/23/Search . While it should be going to /Customer/Search . Somehow it remembers 23 (id) . Here is my routing code in global.cs

Routing to an aspx page on a project with webforms and MVC

安稳与你 提交于 2019-11-30 18:57:51
问题 I've added MVC to an existing webforms project that I've been working on as I'm looking to slowly migrate the project, however, during the change over period I need to be able to access both, but have it default to the aspx pages. When it comes to registering the routing, I currently have this in place: private void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.aspx/{*pathInfo}"); routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapPageRoute("Backup", "{

VirtualPathProvider in MVC 5

瘦欲@ 提交于 2019-11-30 18:43:21
I can't seem to get a custom VirtualPathProvider working in asp.net MVC 5. The FileExists method returns true but then the GetFile method isn't called. I believe this is because IIS takes over the request and does not let .NET handle it. I have tried setting RAMMFAR and creating a custom handler, as in this solution https://stackoverflow.com/a/12151501/801189 but still no luck. I get a error 404. My Custom Provider: public class DbPathProvider : VirtualPathProvider { public DbPathProvider() : base() { } private static bool IsContentPath(string virtualPath) { var checkPath = VirtualPathUtility

MVC InvalidOperationException with custom error pages

谁说我不能喝 提交于 2019-11-30 18:34:53
I have custom error pages setup using <customErrors mode="On" defaultRedirect="~/Home/Error"> <error statusCode="404" redirect="~/Home/PageNotFound" /> </customErrors> I created a page that throws and exception and I get redirected to the correct error pages. However I am noticing these errors in elmah on the production webserver: System.InvalidOperationException The view 'Error' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Areas/Football/Views/Draft/Error.aspx ~/Areas/Football/Views/Draft/Error.ascx ~/Areas/Football