Unable to open a published MVC Project - asp.net-mvc

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.

Related

ASP.NET MVC Displaying Static Help Website

I'm trying to add Help to my ASP.NET MVC project.
The "help" website contains static pages about the features in my ASP.NET application.
I have added the content for this website into my ASP.NET MVC project and have added a hyperlink that will open the Help in its own window.
However, when I try to access the content, the application attempts to route to the Help controller.
How do I display the help website within my MVC application?
I am not sure you can do this within the context of an MVC application. I would consider just building an empty controller with an Index action (HelpController -> public ActionResult Index()) and just return the view name (cshtml file), shouldn't be any reason you can't rename your static html file to cshtml even if you aren't using razor (although I am not 100% sure without trying that the extension change is necessary). Also I would argue that if this ever needs more functionality you have the scaffolding in place to make non-static mods. Disabling routing within the context of an MVC solution honestly doesn't make the most logical sense. The only other choice would be if you hosted it in a different IIS site (but I don't think I would recommend that unless you have a huge help library).
Use IgnoreRoute when you configre your routing, for example, create a folder "help" in your app's root. Then load it with all your html help files. Then to ignore that route:
routes.IgnoreRoute("help");
You should then be able to access it by http://myapp.com/help/whatever.html

Asp.Net MVC route exception

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.

When deploying an ASP.MVC 3 application to a subfolder (not root), how do I handle routes?

I'm developing an ASP.MVC 3 project on my local computer where it is located at the root of the local web server.
localhost:12345/(project is here)
However, when I deploy to our public web server this application will be located in a subfolder
www.mycompany.com/myapp/(project goes here)
How do I deal with that mismatch? A few questions come to mind:
Do I need to adjust my MVC routes? Or will they just capture anything after /myapp/ ?
Do I use HomeController when I don't really want 'Home' to appear in the route? i.e. /myapp/home/(action)/(id) - rather I want this: /myapp/(action)/(id) if Home is the controller.
Should I match this folder structure on my local machine? (This project will never have access to anything outside that 'myapp' folder)
If 3 is yes, how?
I'm using VS 2010 with IIS Express locally.
The routes are relative to the web application. Which means that you don't need to have /myapp/ in your routes.
No you don't need to have Home appear in the route. Personally as a practice I take out the default route.
No you don't need to match this folder structure.
In our experience I found that within the Controllers there is no problem with the routes.
However, if you use HTML helpers within your views, like Html.BeginForm or Html.Action, these do not work with the overloaded methods that receive controller, action arguments. You need to put the whole Url in the Html helpers using Url.Content,
This does not work:
Html.BeginForm()
or
Html.BeginForm("ResetPassword", "Account")
But this works:
Html.BeginForm(Url.Content("~/Account/ResetPassword");

asp.net mvc using HREF in application running on IIS

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.

ASP.NET MVC issue

I have a ASP.NET MVC app and when I run it, it loads my Index action on my HomeController
by default ok.
But when I put in this URl I get 404 - Not Found error
http://localhost/MyGoogleApp/Home/Index
This is the same for any action I put in in Home Controller.
Something fundamentally wrong, any ideas?
Malcolm
You probably have a configuration problem with URL mapping in IIS itself.
I haven't worked much with IIS7, but I think this is what you should check:
Managed pipeline mode should be 'Integrated'.
web.config should include system.webServer with all standard stuff new MVC project puts there (I can't check what exactly right now).

Resources