setup asp.net mvc route for base url - asp.net-mvc

When I have this route setup I can trigger any controllerName/actionName url because I do not need a start url/page.
I do not run a web api because I want to use razor for my views.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "*", action = "*", id = UrlParameter.Optional }
);
}
but when I start my project and run my site I see the base url in the browser: http://localhost:62127/
giving me a 404 error.
How can I configure my project to return a 403 error which is IIS typically giving me? When directory browsing is disabled?

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 }
);
}

How to use URL parameter as a key in MVC application?

In my MVC application , RouteConfig contains following code (by default):
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{key}",
defaults: new { controller = "Home", action = "Index", key= UrlParameter.Optional }
);
}
When a user hits my website (abc.com) or type abc/Home/Index , it invokes Home/Index. Problem is that I want to use key. I mean If a user enters abc/someKey or abc/Home/Index/someKey it should go to Home/Index where i can access that key. It works good in abc/Home/Index/someKey case but fails in abc/someKey & gives exception. Is there any other way to get that functionality ?

URL Routing: a link redirects when not followed by /

I have come across the most bizarre of problems: I have a login page in an MVC application, which when linked by /login will automatically redirect to the home page. However, if I use /Login or /login/, it works!
I have no idea whether it's something to do with a configuration I've messed up, or a configuration in the routing I've played around with, but it happens exclusively with the login page.
I am using forms authentication, and have tried changing the page that you're redirected to from the login page, but that doesn't seem to help at all.
Any ideas?
Update: this only happens on my local machine. I host with Windows Azure, and it works fine when deployed.
Edit: current routing configuration:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Index", action = "Index", id = UrlParameter.Optional }
);
routes.LowercaseUrls = true;
}

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 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