asp.net-mvc-routing

Implementing “Remember Me” Feature in ASP.NET MVC

妖精的绣舞 提交于 2019-11-27 06:21:17
I'm trying to implement a "remember me" feature to my login form. I am using ASP.NET MVC as my web application. I managed to get the cookie stuff working, but I failed to automatically login the user in case he/she checked the remember me checkbox before. I know what the problem is but I do not know how to solve it. In my HomeController I have the following: private LoginViewModel CheckLoginCookie() { if (!string.IsNullOrEmpty(_appCookies.Email) && !string.IsNullOrEmpty(_appCookies.Password)) { var login = new LoginViewModel { Email = _appCookies.Email, Password = _appCookies.Password };

How can I check if a route (ASP.NET MVC) exists for a given path? [duplicate]

走远了吗. 提交于 2019-11-27 05:52:12
问题 This question already has an answer here: How to get RouteData by URL? 2 answers I have a list of local URL’s and I need to determine if they are “valid MVC paths”. How can I check if a URL (path) maps to a MVC controller? Phil Haack's Route Debugger will find a route that match the current request and does so using the current HttpContext. I would like to get this info without building up a mock HttpContext - if possible. 回答1: You can call RouteTable.Routes.GetRouteData with a mocked

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

一笑奈何 提交于 2019-11-27 05:22:16
问题 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",

How do I configure ASP.NET MVC routing to hide the controller name on a “home” page?

不问归期 提交于 2019-11-27 04:56:43
Following on from this question: ASP.NET MVC Routing with Default Controller I have a similar requirement where my end user doesn't want to see the controller name in the url for the landing or "home page" for their application. I have a controller called DeviceController which I want to be the "home page" controller. This controller has a number of actions and I'd like to use URL's like the following: http://example.com -> calls Index() http://example.com/showdevice/1234 -> calls ShowDevice(int id) http://example.com/showhistory/1224 -> calls ShowHistory(int id) I also need links generated

ASP.NET MVC Routing - add .html extension to routes

别来无恙 提交于 2019-11-27 04:38:32
i am pretty new to MVC and Routing and i was asked to modify an app to use diffrent url's. a task that is a bit over me since i have no experience. ok, lets talk a bit of code: routes.MapRoute( "CategoryBySeName", // Route name "products/{SeName}", // URL with parameters new { controller = "Catalog", action = "CategoryBySeName" } ); this works as expected, but then the client wanted ".html" at the end of paths, so i changed: "products/{SeName}", // URL with parameters to: "products/{SeName}.html", // URL with parameters which fails ( IIS 404 page - MapRequestHandler) it seems like iis is

Routing a url with extension in MVC4 won't work, tries to serve up static file

你说的曾经没有我的故事 提交于 2019-11-27 03:54:08
问题 I'm using MVC4 and need to route a request like this to a controller: [myapp]/data/fileinfo.xml Here is the route I have configured: routes.MapRoute( name: "Data", url: "Data/{file}", defaults: new { controller = "Data", action = "fileinfo"} ); Now, this works perfectly fine and routes requests to my DataController if the URL does not include the .xml extension, but as soon as an extension is used, IIS tries to serve up a static file (instead of routing to my controller) and I get a 404 error

ASP.NET MVC Default route?

拟墨画扇 提交于 2019-11-27 02:37:28
问题 I created a new ASP.NET MVC project and implemented a site authorization filter. When I map the routes to the {controller}/{action} pair, I pass a role = "SomeRole" default to the route. It works perfectly if I go through the full url ( http://localhost/somecontroller/someaction ) and I specified the full route MapRoute("SomeAction", "somecontroller/someaction", new { controller = "SomeController", action = "SomeAction", role = "SomeRole"); The problem is that when somebody visits http:/

AreaRegistration.RegisterAllAreas() is not Registering Rules For Area

主宰稳场 提交于 2019-11-27 02:21:50
问题 I have an MVC 4 web application which consists some areas. I have a problem with the routing rules of an area named "Catalog". The RouteConfig.cs file is: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, ); } and Global.asax as follows: protected void Application_Start() {

mvc Html.BeginForm different URL schema

人盡茶涼 提交于 2019-11-27 02:13:25
I'm creating a form for a DropDown like this: @{ Html.BeginForm("View", "Stations", FormMethod.Get); } @Html.DropDownList("id", new SelectList(ViewBag.Stations, "Id", "Name"), new { onchange = "this.form.submit();" }) @{ Html.EndForm(); } If I choose a value from my dropdown I get redirected to the correct controller but the URL is not as I would like to have it: /Stations/View?id=f2cecc62-7c8c-498d-b6b6-60d48a862c1c What I want is: /Stations/View/f2cecc62-7c8c-498d-b6b6-60d48a862c1c So how do I get the id= querystring parameter replaced by the more simple URL Scheme I want? A form with

Routing with and without controller name in ASP.NET MVC 4

↘锁芯ラ 提交于 2019-11-27 02:11:57
问题 I'm using ASP.NET MVC 4 and I have some problems settings up my routes. Could you tell my how to set up my routes to point urls to actions as follows: "/" (or "/Start") => PublicController.Start() "/About" => PublicController.About() "/MyPage" (or "/MyPage/Summary") => MyPageController.Summary() "/MyPage/Invoices" => MyPageController.Invoices() "/MyPage/Invoice/72" => MyPageController.Invoice(int id) It's the url "/About" that messes things up for me, i.e. a url that does not specify the