asp.net-mvc-routing

ASP.NET MVC Routes: How do I omit “index” from a URL

▼魔方 西西 提交于 2019-12-02 13:52:07
问题 I have a controller called "StuffController" with a parameterless Index action. I want this action to be called from a URL in the form mysite.com/stuff My controller is defined as public class StuffController : BaseController { public ActionResult Index() { // Return list of Stuff } } I added a custom route so the routes are defined like this: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); // Custom route to show index routes

Removing Controller from url in a specific scenario

穿精又带淫゛_ 提交于 2019-12-02 11:22:56
I want to remove Controller named Home from url when user clicks on About and Contact pages in ASP.NET MVC sample application . I tried this but it is giving me a 404 error. routes.MapRoute("Home", "{action}/{id}", new { controller = "Home" }); When i remove this all works perfectly. Note I want to remove Controller name only when Controller is Home. Other Controller should remain same. Further I kept the code in Route.Config file above routes.MapRoute("Home", "{action}/{id}", new { controller = "Home" }); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new {

mvc routing generates iis 7.5 error forbidden

主宰稳场 提交于 2019-12-02 10:15:49
I my WebApplication I have an ASPX WebForms Page here: ~/ASPWebforms/MyFolder/Default.aspx If I use this code: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapPageRoute( "SomeRoute", "Test/{reportname}", "~/ASPWebforms/MyFolder/{reportname}.aspx" ); and then enter this in the browser: localhost/MySite/Test/Default I get the desired the result: The page ~/ASPWebforms/MyFolder/Default.aspx is displayed. But if I use the following code routes.MapPageRoute( "SomeRoute", "Test/", "~/ASPWebforms/MyFolder/Default.aspx" ); and try

Custome MVC Url Rout to display mixture of Id and UrlSlug

二次信任 提交于 2019-12-02 08:52:11
Hi ' I'm gonna to apply the mixture of Id and slug as a url in my blog url like this http://stackoverflow.com/questions/16286556/using-httpclient-to-log-in-to-hpps-server to do this I have defined this Url in my global.asax routes.MapRoute("IdSlugRoute", "{controller}/{action}/{id}/{slug}", new {controller = "Blog", action = "Post", id = UrlParameter.Optional,slug=""}); but when I run my application Url is look like this : http://localhost:1245/Blog/Post?postId=dd1140ce-ae5e-4003-8090-8d9fbe253e85&slug=finally-i-could-do-solve-it I don't want to have those ? and = in Url ! I just wanna to

How to generate a path/url from a Route in the Routes table?

别说谁变了你拦得住时间么 提交于 2019-12-02 08:38:55
I have an ASP.NET MVC web application, and I've registered a number of routes in my Global.asax. I would like to know how I can programmatically build (generate a string url) any one of those registered routes from within my Controller. I did the same thing in Web Forms with .NET 4.0 using Page.GetRouteUrl(routeName, routeParams) but can't figure out how to do the same thing in MVC (I'm an MVC newbie). You could use the UrlHelper class inside your controller action. public ActionResult Index() { string address = Url.RouteUrl(new { action = "foo", controller = "bar", id = "123" }); // TODO: do

Domain dependent routing ASP MVC 3

北城余情 提交于 2019-12-02 07:17:12
I have two domains: mydomain.com and mydomain.fr They both correspond to the same IP address. I want users typing mydomain.com to view page A (Controller = "Application" Action = "A" ) and users typing mydomain.fr to view page B (Controller = "ApplicationFR" Action = "B" ) I am using ASP.NET MVC 3 and the default route is mapped to page A. How can I achieve this ? EDIT: I tried to use the example provided but it seems not to work. Is it the right way to register the custom route ? public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

How to make one controller the default one when only action specified?

独自空忆成欢 提交于 2019-12-02 07:12:04
I am using the standard MVC template from MVC 2013. There is a Home controller with actions About, Contact, etc. There is an Account controller with actions Login, Logout, etc. The app is deployed at domain website . The url http://website will produce the output of /Home/Index, without changing the url in the browser address box, ie what the browser shows is not the result of a Http redirect. How do I make the url http://website/X route to /Home/X if X is not another controller in my application? Otherwise it should route to /Home/X/Index. The reason is that I would like http://website/about

trailing slash issue in IIS 8.5

江枫思渺然 提交于 2019-12-02 06:24:56
问题 We are moving a ASP.NET project from IIS6 (Win Server 2003) to IIS 8.5(Win Server 2012 R2). The project has some MVC components for which the following routing is used. routes.MapRoute("simple", "{controller}.mvc/{action}/{id}"); routes.MapRoute( "Default", "{controller}.mvc/{action}/{id}" new { controller = "Home", action = "Index", id = "" } ); Thus call to MyDemoController would be accessed by MyDemo.mvc Now what happens, when I use the url as MyDemo.mvc/ it works, but when I use MyDemo

WebApi - action paramer is null when using [FromBody] attribute and POST method

眉间皱痕 提交于 2019-12-02 06:16:07
问题 I have this controller and I can't figure out, why name parameter is null public class DeviceController : ApiController { [HttpPost] public void Select([FromBody]string name) { //problem: name is always null } } here is my route mapping: public void Configuration(IAppBuilder appBuilder) { HttpConfiguration config = new HttpConfiguration(); config.Routes.MapHttpRoute( name: "ActionApi", routeTemplate: "api/{controller}/{action}" ); appBuilder.UseWebApi(config); } and here is my request: POST

RequestContext - RouteData does not contain action

落花浮王杯 提交于 2019-12-02 05:01:12
问题 So i've created my own ControllerFactory and i'm overloading GetControllerSessionBehavior in order to extend the MVC behavior. To do my custom work i have to use reflection on the called action. However i've stumbled upon a weird issue - i can't retrieve the action by accessing RequestContext.RouteData While setting up a reproduction sample for this i was not able to reproduce the error. Is anyone aware of possible reasons for this or knows how to retrieve the action by calling a method with