404 - File or directory not found in ASP.NET MVC - 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

Related

How to open static html file in asp.net mvc without controller & view

I have some HTML files that are stored in a folder and I want to open these HTML files.
I added the below code in the route.config file:
routes.IgnoreRoute("{file}.html");
routes.MapRoute(
name: "Default",
url: "{about.html}",
defaults: new { controller = "About", action = "Index", id =
UrlParameter.Optional });
Now this about.html url has created and on about controller Index Action I have called view. so it is working but I am open directly file from folder then it is not opened.
I am facing the error
HTTP Error 500.0 - Internal Server Error
Internal Server Error
Most likely causes are:
IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.
IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
IIS was not able to process configuration for the Web site or application.
The authenticated user does not have permission to use this DLL.
The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.
I want the path to be example.com/Folder/test.html.
I have dynamic pages for that I have created Route is as below
routes.MapRoute(
name: "Article",
url: "article/{name}.html",
defaults: new { controller = "Article", action = "Index", id = UrlParameter.Optional }
);
When I added the above route for .html extension then above route not worked so I changed configuration in web.config. after that it has started for working. but when I call to static html file it was showing me error.
so for that I crated below code in my controller and finally I received a solution
public ActionResult Index(string page)
{
var pageRoute = "~/uploads/" + page + ".html";
var staticPageToRender = new FilePathResult(pageRoute, "text/html");
return staticPageToRender;
}

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.

Deploy ASP.NET MVC on virtual directory

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?

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.

How RedirectToAction determines when site is consumed from Internet?

I've been working on a Web site with ASP.NET MVC version 1, deployed in a Windows Server 2008 R2 (IIS7, integrated mode). The site works well in intranet enviroment, but recently was published in Internet with a public domain name. RedirectToAction still aims to private IP, causing redirect to login page. Where I can specify the change?
For notAnExpert petition, an extract of my code. Nothing special here, only the default conventions:
return RedirectToAction(string.Format("Details/{0}", CampaignId), "Campaigns");
In my Global.asax neither:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("clicked_links", "Clicked/Index", new { controller="Clicked", action="Index"});
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
My fault guys, in the view I find this
<form action=<% Request.URL %>
Additionaly the web server was misconfigured.

Resources