I have an mvc site deployed at godaddy server. The mvc routing is working fine on my system and i tried to deploy it on my free azure subscription to test. Its working there. My route.config file has nothing new:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
On server, i have a virtual directory named "httpdocs". None of the controller is receiving my call and giving error 404 page not found. Can you please assist as to wat other changes do i need to check as it seems related to deployment on godaddy server. Please feel free to let me know if any other information seems missing here so that i can provide additional details.
Ok, After spending almost 2-3 days on it, i finally figured it out. My application is using MVC 5.2 Version and goDaddy provides support for max MVC 5 version.
So after downgrading MVC FROM 5.2 to 5 version, it worked.
This may help someone else who might face this issue.
Related
Using MS Visual Studio 2022 on Windows 10 pro to build an ASP.NET Core MVC for the first time. When this tutorial (https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/start-mvc?view=aspnetcore-6.0&tabs=visual-studio) has me run it, Localhost comes up with some stuff relating to the app (its name, a welcome message). The tutorial says to then add "/MvcMovie/" to the URL in the address field. Then, localhost says "No webpage was found for the web address: https://localhost:44379/MvcMovie/".
I'm new at this. Not sure from the tutorial when/if to actually add something to localhost.
Any help will be appreciated.
If you are refering to this:
In the Configure your new project dialog, enter MvcMovie for Project
name. It's important to name the project MvcMovie. Capitalization
needs to match each namespace when code is copied.
The tutorial is saying that your Project's name should be MvcMovie when you create it. Other than that, the tutorial doesn't ask you to go to localhost/mvcMovie. To figure out the routing in an MVC check the next few parts about Controllers-Views-Models. There will be explained about the routing part and how you can access different parts of the URL.
The MvcMovie mentioned in the document does not require you to enter in the URl, it is just the name of the created project:
If you need to use MvcMovie as the routing address in the Url, you can do this:
Controller:
[ApiController]
public class TestController : Controller
{
[HttpGet]
[Route("MvcMovie")]
public IActionResult MvcMovie()
{
return View();
}
}
View demo:
<h1>This is MvcMovie Controller!</h1>
Test url:https://localhost:7040/MvcMovie
Result:
I think you need to know the routing rules in mvc, you can read this document:
Routing to controller actions in ASP.NET Core
I was recently tasked with fixing one of our Help Pages that had gone down. I hadn't ever worked on one before, so I jumped in and started playing around with it. I noticed we had this route set up for the Help Page:
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"HelpPage_Default",
"api/v1/Help/{action}/{apiId}",
new { controller = "Help", action = "Index", apiId = UrlParameter.Optional });
HelpPageConfig.Register(GlobalConfiguration.Configuration);
}
I compared it to another working Help Page route and found the url to be different. I changed the url to
"Help/{action}/{apiId}"
and it worked. I've done some research online (this helped) but still fail to understand why changing the url would make any difference on whether that page would be hit. It would make sense to me that if I went to mydomain.com/api/v1/Help that I would still hit the help page with the original url.
Thank you in advance.
Route what you have "api/v1/Help/{action}/{apiId}" this is wrong because format of the route should be [Controller]/[Action]/[Id] and your controller is Help not "api/v1" .
And to answer your question to "mydomain.com/api/v1/Help" this url hitting the help page, yes it will if you give "help/{action}/apidid" url in the route.
"api/v1" till here its your IIS virtual directory setup not a route in your application configuration.
I'm getting a 404 not found error when trying to access one of my Web API actions:
I have in my WebAPIConfig:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
I have a controller named OnSourceAPIController and a GET action ValidateServiceRequestAuto.
I get a 404 error when I try to go to:
http://localhost/api/OnSourceAPI/ValidateServiceRequestAuto
My first guess was I had some kind of routing error, but I created an mvc controller and an index page for it and was able to browse there normally via this routing (api/controller/action). The builtin api/help page even shows /api/OnSourceAPI/ValidateServiceRequestAuto as the route to my api call.
I also tried using the WebAPIRouteDebugger tool. It gives me a 000 404 not found error when I use
http://localhost/api/OnSourceAPI/ValidateServiceRequestAuto
, but actually give me the normal route information if I take localhost off of the front and just use
api/OnSourceAPI/ValidateServiceRequestAuto as the URL...
Any pointers would be appreciated.
I figured it out and feel a little bit silly now.
I have my webapi project running inside of my normal website project with a path of .../api, so because I set up my api routing to be api/controller/action, the path I really need to use is localhost/api/api/controller/action. So it turns out that the 404 was there because it really couldn't find anything at that location. I hate it when computers do exactly what you tell them to.
In my case it was address of created service: WebApp.Start(address)
Should be like: http://localhost:9000/
NOT: http://localhost:9000/api/
I'm with the following issue: when I try to access a certain page (http://mysite.com/Client/) I get an Access Denied error (403 - Forbidden: Access is denied), but if I try to access the same URL using "Index" in the end (http://mysite.com/Client/Index), it works! And I have a lot of another folders that work without the "Index" in the URL.
The wierdest part is that in the test server (http://mysite.com:8080) I can access in both ways (/Client/ and /Client/Index/). By this time I don't know if it's an IIS 7 problem, or in the Client Folder for some reason, if it's in Web.config or if I'm just losing my mind!
The routes are the following:
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
);
One more thing: the test server app and the main server app are the same!
Can someone give me a hand? Thank you!
P.S.: There isn't any authorization setting in web.config.
From your question it seems like you don't have a Client controller, just folder. So, I guess the route is looking for a controller that It can't find. Or you have a controller but no actions in it. I am not sure, anyway, try adding this to your routes:
routes.IgnoreRoute("Client/{*path]");
EDIT:
Try adding this route:
routes.MapRoute(
"Default", // Route name
"{controller}/Index", // URL with parameters
new { controller = "Home", action = "Index"}
);
resolved in a mysterious way: although I tried to resolve things editing the routes, I realized that the error was occurring before the application_start event. So, the problem was in IIS.
I tried to find the reason for the problem, but I couldn't, so I installed the URL Rewrite 2.0 and made the request of "/Client" redirect to "/Client/Index".
Wierd, isn't it? But this workaround resolved!
Thaks for all the answers!
I have an existing ASP.Net Application, into which I am attempting to introduce MVC2.
Hopefully I can remember the steps, but what I did was the following:
Created a dummy MVC2 project.
Compared and merged .csproj, resulting in the Add Item commands showing MVC2 items.
Compared and merged the web.config
Compared and merged the global.asax.cs
Added Models, Views and Controllers directories
Added HostController with Index action and Index.aspx (no logic)
Amended route to make /Host/Index the default
So now, when I access the application via the root address http://localhost/MyApp it all works.
But, when I access http://localhost/MyApp/Host/Index I get a 404 error. I get the same result for any of the Controller/Actions I created. The only way I can get them to appear is to use the defaults in the routing configuration. I installed Phill Haack's route debugger and it's doing nothing. Obviously there's some problem with my routing, but I can't figure it out.
Any ideas what I've missed?
Bah... turns out that this is to do with IIS 5.1 and MVC routing.
I resolved it by using the following Routes in my application (note the .aspx extensions).
routes.MapRoute("Root", "", new { controller = "Host", action = "Index" });
routes.MapRoute("Default", "{controller}/{action}.aspx", new { controller = "Host", action = "Index" });
Means I can't have clean routes, but at least it works.