Loading an MVC site - model-view-controller

Hello I am in desperate need of help. I just created an MVC site made in Visual Web Developer 2010
and each time and on different Web Hosts I get --Index of /-- instead of the site loading properly. It's as if the server or browser is looking for an 'index' file instead of being routed through the MVC folders to the proper start up page. I've done everything I believe I am suppose to do as far bring all my dll 'system' files to the 'bin' folder as well as everything else including getting a Web Host that has MVC supporting server but I still keep getting 'Index of /' and the folders instead of the site. Can anyone help? I'm really in a spot. I've been working on this site for months and I need to get it up and running.
Thanks, Rob

It looks like your default route is not setup or the setup is pointed to a place that doesn't exist. Your default route will be in the default.asax.cs page (MVC4 is App_Start/RouteConfig.cs) and looks something like this:
routes.MapRoute(
"Default", // Route name
"", // URL with parameters
new { controller = "Home", action = "Index"} // Parameter defaults
);
So the the Default action is Home/Index. You can change this if you want to redirect to a different default page.

Related

How to remove directory name from url with global.asax code

I am using MVC routing in asp.net Web forms and I want to remove the folder/directory name appended in the URL. Locally this works fine but I have the following address now appearing on Godaddy shared hosting.
www.mywebsite.com/my-folder/contact
but I want like this
www.mywebsite.com/contact
I have tried web.config techniques but no success that's why I am asking is there any way to redirect this using Global.asax.

.aspx redirect to Umbraco 5 page

I have custom Area in my Umbraco 5 web application named "en", i want to redirect my old links(prior to Umbraco 5 on other sites) to new ones automatically,
in my Area Registeration File i have mapped the new Route as
context.MapRoute(
"en_Home",
"en/{url}.aspx",
new { action = "HomeRedirection", controller = "Redirection"}
);
but it gives me "The resource cannot be found", if i remove the .aspx Bit it works, i created a simple mvc3 application to test my code there and it all worked fine with ".aspx" links redirecting normally with the code above, i don't know what i am doing wrong, any help will be appreciated.
Thanks in advance,
Sher

deploying asp.net mvc 3 website

I'm trying to deploy my finished website to the hosting company server and i'm basically stuck. I have wwwwroot folder on the server where I put my folder of the published project. So what is the index file, the first page that I should display.. is it the layout page or simply my index.cshtml or maybe the _ViewStart? I got to create a path to the folder where the file would be located and give them the name of the "index page". I've been trying to do this for a while now with no luck.
Your default route should go to the default controller/view (ie /home/index)
So if someone visits your site at www.yoursitewhatever.com it will automatically find the default page.
Here is a link that might help you and explain the differences between previous MVC versions .
http://haacked.com/archive/2011/05/25/bin-deploying-asp-net-mvc-3.aspx
A default project creates the default page in the global.asax file that is why by default it is located in home/index folder as in
routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults );

MVC3 - How do I route to a subsite?

I have a subsite within my main site for site Administration. The site is physically stored in the form
~/Views/Administration/ViewName/Index
With controllers inside
~/Controllers/Admin/ControllerName
I am getting an exception trying to visit the page.
The view 'index' or its master was not found or no view engine
supports the searched locations. The following locations were
searched: ~/Views/ViewName/index.aspx ~/Views/ViewName/index.ascx
~/Views/Shared/index.aspx ~/Views/Shared/index.ascx
~/Views/ViewName/index.cshtml ~/Views/ViewName/index.vbhtml
~/Views/Shared/index.cshtml ~/Views/Shared/index.vbhtml
I added a route
routes.MapRoute(
"Administration", // Route name
"Administration/{controller}/{action}/{id}", // URL with parameters
new { controller = "Administration", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
Going directly to the page manually
http://localhost:999/Administration/BaseItem/index
Does not result in exception, but I get no content. This leads me to believe it is not finding the View. What am I doing wrong?
I think the issue is that I have told the route engine how to route to the Controller, but I have not told the system how to route to the View. Where do I tell the system where the views are?
The problem is not with the routes, but with the design. The view engine cannot find your view, because it cannot find the correct path, since the default view engines are not designed to search for a subsite.
Instead of creating a subsite, make Administration an Area in your project. In AdministrationAreaRegistration.cs, you will set a route similar to the route you added. Place your views in the Views folder inside the Administration folder (inside the Area folder), and everything will work properly.

MVC3 start page

I am working on a web app in Visual Studio 2010, its mvc3. I Was trying to figure out how to publish it, and through various instructions I tried setting View/Home/Index as the start page. This was a bad idea. Now nothing is working, even trying to view the site as I have been (debugging with F5) is not loading properly.
I don't know what the start page was before, or how to undo this. I am very new to web development, and a little lost right now. How do I get my start page back?
Go to the project's Properties
Go to the Web tab
Select the Specific Page radio button
Remove url in the Specific Page text box
Save Properties Tab.
Try setting the start page to /.
If you leave it alone after set up, it should be like so:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
My suggestion is leave it like that. How do you "get back"?
Simple: Open another instance of Visual Studio. Create a blank MVC3 project. Copy over the routing rules and add custom rules (if any) below. Copy over the web.config with any customizations you have made (if any).
Then, right click the project and select publish. If you publish to a local folder, you will have to set up IIS properly, but you can work through the kinks on your local IIS instance (assume you have installed it, as this is a developer machine?). Once you know the set up, you can move to the server and you should be fine.
That is about all of the time I have for this one right now. Good luck!
i know this is an old post... but whoever comes after this would find the piece of info helpful
if you want to change the start up page in MVC3 u can do so by just specifying like this
Specify Page: Account/Logon
No need to include the view name if you say Views/Account/LogOn it would return Resource not found error and if you include / it would say bad request.
I tried the above option and could change my start up page from the annoying index page to LogOn.cshtml
Simply change your starting url to /Home/Index or / (or remove it) - you cannot address items directly in the /Views folder.
Try creating a new html file in the main project and set it as the default. Then delete the file. That should remove the start page. You do not need one for Mvc.
Right click on project --> Properties
Go to the Web tab
Select the Specific Page radio button
Specify the start page as ControllerName/ActionName as it comes in the browser url when the page is loaded
Save.

Resources