Deploy ASP.NET MVC on virtual directory - asp.net-mvc

When i return View() from my action, result URL was not include virtual directory name.
expect for this
...../MyMVCApp/Controller/Action
but i got this
..../Controller/Action
How can i fix this problem?
Thank you in advance.
EDIT:
My RouteConfig.cs is
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Con", action = "Index", id = UrlParameter.Optional }
);
and on IIS(6.1) I just add application on the some root site like this
Website
|
|- MyMVCApp
|- OtherApp

This shouldn't be an issue at all as long as your virtual directory is a web application in IIS. If you have configured your project as a web app and you still have issues then it should be a routing problem.
By saying that, I believe your issue is IIS configuration or a routing problem. Can you paste a screenshot of your IIS structure and how you are registering your routes?

Related

Problems deploying mvc app to sub directory of site

When i place all my files in the root of my site, it overrides the existing site and automatically goes to the calendar application instead of the index.php that i have.
I have an existing site that i cannot change, so i was wondering how i can deploy this in a subdirectory, ex mysite.com\mvc_app\Home\Index
Here is my routing for the route config, any help would be appreciated! (i tried ignoring the blank route but it seems to open the app still, even tho hostbuddy is set to route mysite.com to the index.php as the default page)
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}

MVC Site not working when published to web hosting provider

I am trying to publish an MVC site. The website/application are both setup for .NET Framework 4. When the site is published, the MVC page gives the following error:
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
Also if I try to bring up a test aspx file, I get this error:
"The resource cannot be found."
The first test I perform is to delete the web.config. At this point, I attempt to bring up an MVC page again and same error is displayed:
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
However, if I try to bring up a test aspx page now, I actually get the page:
1 + 2 = 3
The test aspx page just contains this:
<html>
<body>
1 + 2 = <%=(1+2).ToString() %>
</body>
</html>
Any help of what to check next would be appreciated. Saw similar threads where it mentions of adding:
<customErrors mode="Off" />
and
<asp scriptErrorSentToBrowser="true"/>
But that still gives me the same error when bringing up a MVC page. Any help on how to proceed next to fix this MVC site would be appreciated. Thanks.
Update #1
I did a search for the keyword "routes.MapRoute" in the entire project and found it only once in the RouteConfig.cs:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
The page I am testing is:
http://.../Home/Index
This is the page that returns:
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
I found the problem! The problem was that the website hosting provider had the website setup for IIS 6.0. In that case there are two options:
Update hosting site to support IIS 7.0. This was my solution and solved the problem
Set the MapRoute to run a "fake" aspx page: (only do this if you cant update hosting to IIS 7.0):
// IIS 6.0
routes.MapRoute(
name: "Default",
url: "typehereanything.aspx/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Using this second method is not recommended since now you have to plug in "typehereanything.aspx" into every URL: http://.../typehereanything.aspx/Home/Index
Any of those two options solved the issue.

404 - File or directory not found in ASP.NET MVC

I am developing a MVC web application. Testing locally
http://localhost:28847/Place/Malaysia works perfectly how ever, When I deploy this web application in hosting server
http://videeows.com/Place/Malaysia I get 404 - File or directory not found.
The app is deployed in asp.net version 4.5 in the server.
What could have possibly gone wrong?
There are other MVC sites deployed in the machine which works perfectly.
my MVC is just a redirection.
http://videeows.com/Place/Malaysia this will redirect to http://videeows.com/Place.aspx?s=Malaysia&q=Coun
http://videeows.com will direct to http://videeows.com/default.aspx
my routeconfig is:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Place",
url: "Place/",
defaults: new { controller = "Place", action = "Index" }
);
routes.MapRoute(
name: "PlaceByCountry",
url: "Place/{country}",
defaults: new { controller = "Country", action = "IndexByCountry", country = "" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { id = UrlParameter.Optional });
}
This is unlikely to be a problem with ASP .NET MVC code. It must be to do with the way you have set-up the server. It's difficult to say what it is though. Make sure that your app pool supports the .NET version which you are using etc.
Check your IIS Server settings and App pool you are using. Just fire and check http://localhost:8080/ IIS working
Make sure that your app pool supports the .NET version which you are using.
I've had the same problem : for certain pages, I get a 404 Error message. In fact is that the server does not consider the last part of the URL as an "id", but instead a folder name. And indeed this folder doesn't exist. I think it can happens when a link is just a call to RedirectToAction to another function...
A solution can be, Instead of using :
AreaName/ControllerName/FunctionName/IdReference
use
AreaName/ControllerName/FunctionName?Id=IdReference

Using namespaces in RegisterRoute (MVC)

I have a solution with multiple projects. One of my projects only contains controllers. Another project contains my Views.
In my Views project, I've added namespaces in my RouteConfig.cs but I keep getting an error when I run my project:
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its
dependencies) could have been removed, had its name changed, or is
temporarily unavailable. Please review the following URL and make
sure that it is spelled correctly.
Requested URL: /
Version Information: Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.0.30319.17929
This is my RouteConfig.cs
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
namespaces: new[] { "AS.Core.Controllers" },
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
My HomeController.cs' namespace is namespace AS.Core.Controllers.Home
Setup:
Solution: AS.Core
-- Project: AS.Core.Controllers (controllers only)
-- Project: AS.Core.Web (views/scripts/css/images)
Under my controllers project I have multiple folders, such as "Home" and "Assets". I then have a controller in each folder so, I have "HomeController.cs" in the Home folder and "AssetsController.cs" in my Assets folder.

How to set asp.net mvc routing for deployment in windows azure?

I am working on Asp.net mvc 4. I am trying to deploy my project on windows azure as a webrole. I have made caustom routes in global.asax(i.e. RouteConfig.cs) file like,
routes.MapRoute(
name: "DefaultConn",
url: "{id1}/{id2}",
defaults: new { controller = "mycontrollername", action = "actionname", id = UrlParameter.Optional }
);
It actually works in local environment. But when i publish my website into windows azure environment it shows 404 Page Not Found Page.
I have accessed the page with the following url,
http://xxx.cloudapp.net/mmdg/kli
It gives 404 page not found exception. so please guide me.

Resources