I have an existing ASP.NET webforms website and I have two pages that are ASP.NET MVC that I want to have coexist on the same site.
It works fine except for default documents -- I want htp://localhost to show localhost/default.aspx. Currently:
htp://localhost/ displays the MVC page which should be: htp://localhost/TestPage/Index
htp://localhost/default.aspx displays the webforms page (as it should)
There's nothing special in the RouteConfig.cs -- I'm just using this:
routes.MapRoute(name: "MVCPage",
url: "{controller}/{action}/{id}",
defaults: new { controller = "TestPage", action = "Index", id = UrlParameter.Optional } );
You can add an ignore route statement.
routes.IgnoreRoute("default.aspx");
https://weblogs.asp.net/pjohnson/mvc-s-ignoreroute-syntax
http://www.c-sharpcorner.com/UploadFile/f82e9a/ignore-route-in-mvc/
https://msdn.microsoft.com/en-us/library/dd505203(v=vs.118).aspx
Related
I am using ASP.NET MVC, In localhost, using the web, I changed the start URL option it works fine there, once I published it to the main domain, it is not working on that. I hope anyone can help me. I want to redirect from
domain.com/
to
domain.com/Home/Index
Thanks a lot!
you need to change your default route as this
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
on startup the default route is initialized and hence redirected to the above website as
domain.com/Home/Index
I have a page created on VS13 MVC 5 based on ASP.NET, on my navigator I have my dropdown menu
While I click on Phones link I have URL as: www.sitename.com/phones and it will list all phones which I have on my data base, while I choose a brand (e.g: Samsung) I want my URL will be www.sitename.com/phones/samsung
Simple question I don't want create a view for each brand or model of phone because there are a lot, I can just use SQL and list them on the same page but how to change my URL depending on my choice ? Is the only way is Attribute Routing?
Appreciate any suggestion.
If you are using JS/jQuery you can use the History.js api. https://github.com/browserstate/history.js/
You can then use History.pushState(insert parameters here);. This will not only change the url to your choice but also allow users to go back and forward like usual, it also keeps SEO with web crawlers I think.
You can add a Route to your route config
in RouteConfig.cs
routes.MapRoute(
name: "Product",
url: "{controller}/{productCategory}/{productName}",
defaults: new { controller = "Product", action = "Index", productCategory = UrlParameter.Optional, productName = UrlParameter.Optional }
);
in product controller
public ActionResult index(string productCategory,string productName)
{
//return items by productCategory/ProductName
}
I'm use visual studio 2012 with MVC4.
I want some web page looks like .html suffix. So I add this code on RouteConfig:
routes.MapRoute(
name: "Static",
url: "{controller}/{action}/{id}.html",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
But the problem is I can't access it, the page always returns 404, and shows message:
the resource is not found or removed.......
Is there any way can let it route as html page? thanks
Disable the handler for the .html extension.
I currently got a problem with the namespaces I added this into my global.asax:
routes.MapRoute(
"Admin",
"Admin/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
null, new string[] {"project.Controllers.Admin"}
);
Now my controller is being reached when I type into the url localhost/Admin/Controller/*
Put my controller isn't giving me the right Views. It's giving me the View in Controller/Views. And I want the Views located in Admin/Controller/Views. I tried linking to them directly but thats not going to well. Any idea how this is done?
If you're using ASP.Net 2 or higher, you probably should be adding this Admin section as an ASP.Net MVC Area. Areas are like mini MVC sites with-in separate folders, which should solve your question.
I have added a new Controller to my application, and then from there added in a new View (right click, add view on the context menu)
I have added the route to the Route table, but when I browse to it I get a 404.
I can only assue that this is something fundamental that is wrong, as if I replace the values in the default route, I still cannot access my page.
The route table is;
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Classroom",
"{controller}/{action}/",
new { controller = "Classroom", action = "Index" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
//defaults: new { controller = "Classroom", action = "Index", id = UrlParameter.Optional }
);
there is only a return View(); in the index method. I have installed Glimpse, but as I am getting a 404, I cannot actually see the url that is being passed back.
So, what techniques / tricks are there I can use to track this down, (and any common gotcha's that could be causing this?)
Visual Studio 2012, using the inbuilt webserver.
This is Fixed. It was a stupid Gotcha on my part. The Controller was Called Classroom not ClassroomController
I have added the route to the Route table
No, you don't need to add any route for that. Get rid of the Classroom route from your Global.asax and leave only the Default one. Now you could safely navigate to your controller using /classroom/index which will render the Index action of the ClassroomController.