In a mvc project that we have developed for 6 months to now, we don't want to change the url when redirecting to another view. For example, our domain is xyz.net, we want customers to see only our domain name in url. Is it possible? Can we do it with mvc routing?
When we use return View("ViewName"), url is not changing. Is it meaningful to use for all in project for not changing url?
Now project contains RedirectToAction("ViewName", "ControllerName") for redirection between views, and it is changing url like "xyz.net/controllername/viewname".
How can we do without using url routing?
Related
I am trying to setup my MVC application to only accept lowercase URLs with routes.LowercaseUrls = true; within route config file but It seems it isn't working the way it is supposed to be.
For example I can access my MVC web app home page with both of below URLs.
http://localhost:58482/Home/indeX
http://localhost:58482/home/index
I want my application to change any uppercase letter in URL to lowercase. Is it possible?
Your help is much appreciated.
I'm a total beginner so sorry in advance.
I used VS13 to build a MVC project and published it to my webspace. Now I'm unsure which file or path I need to specify in my forwarding config in order to open the website.
I tried
/Views/Shared
to get _Layout.cshtml and
/Views/Home
to get Index.cshtml but none of these are working. I also changed some admissions but it always shows me this
Forbidden - You don't have permission to access / on this server.
when I'm trying to open the website.
Any ideas on what I'm doing wrong?
With MVC You don't access views like traditional ASP.NET WebForms i.e. /path/to/view.aspx. Everything is handled via routing & controllers.
By default you will have a HomeController which will have an Index action which is invoked via a GET request. Assuming you haven't changed any of the default routing configuration you would just need to navigate to www.domainname.com/home to see your Index page.
The default routing configuration looks like /controller/action/parameters, MVC will always work this way unless you tell it different. If you don't pass a specific action (like I didn't with the home url) the Index action of the controller is assumed.
I am using MVC to develop my website. I am getting the following errors.
URL:http://www.abc.com/robots.txt
1. The controller for path '/robots.txt' was not found or does not implement IController.
URL:http://www.abc.com/blogs/post/whats-new-in-mvc
2. The controller for path '/blogs/post/whats-new-in-mvc' was not found or does not implement IController..
But i dont have the above mentioned url in my website. How the above url are generated? Can you please let me know the solution to fix the above issue?
The first one is used by search engines to index your website. It's a good practice to have a robots.txt file to your application. So you could add this file to the root of your site. As far as the second url is concerned, I have strictly no idea who is querying it. Maybe somewhere inside your site you have a link to this url?
But if you don't want to use this file you could exclude it from routing:
routes.IgnoreRoute("robots.txt");
Now when a search engine sends a request to this file he will also get a 404 but the request won't be routed through the MVC pipeline.
There is a partial view representing pager control (very similar to this) for blog content. Code generates HTML with references and href like, "/Blog/Posts/Page/1", "/Blog/Posts/Page/2" etc.
It worked absolutely fine on Cassini, but after I switched to IIS problems appeared.
IIS application running in virtual folder, so URL is
http://localhost/tracky
and blog area located,
http://localhost/tracky/blog
As I press on pager button, I recieve 404, because the URL would be
http://localhost/blog/page/3
Instead of
http://localhost/tracky/blog/page/3
My question is, how to handle such situation? how to change code generation to provide correct URL? how to make it work same - as root applicaton or application in virtual folder?
Source code is here
You need to generate your urls either by using ActionLink in your view, or using an UrlHelper in your href as follows: <a href="<%=Url.Content("~/blog/page/3")%>" ..>bla</a>. This will generate Urls that are adjusted accoring to your application root.
You should be using the following:
UrlHelper.GenerateContentUrl("~/Blog/Posts/Page/1");
The ~ allows the url to be resolved relative to the application path and should produce correct results in both cassini and IIS.
I have a web server that has existing pages in it that are created with basic static HTML. I want to leave them alone, but augment the site with some ASP.NET MVC pages. I want these pages to be reachable via the MVC URL routing mechanism. But, ideally, I want to preserve the old static pages URLs without having to bring all those static pages into the MVC app. What's the best way to accomplish this?
Static files such as .html pages that exist on disc will be directly served by the web server. If you are hosting your application in II7 integrated mode you could try adding the following route:
routes.IgnoreRoute("{file}.html");
By default routing is not applied when a physical file exists which could be turned off by using routes.RouteExistingFiles = true;.