Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there something special about a MVC controller called properties?

After trying to work this out for ages, thinking about routing conflict and more - I started a separate project from the start.

It looks like an MVC controller called "properties" always returns a 403.14 forbidden message when you try to access the root site (http://site/properties) - however, other pages work (http://site/properties/index).

It works fine as a controller in an area, but, I just can't create it in the main site.

I was wondering if anyone knows why and what the best way round this is?

like image 578
Wil Avatar asked Dec 14 '15 09:12

Wil


People also ask

What is Property in MVC?

MVC Properties are the following: Loose Coupling. Light weight code. Effective looks. More Security.

What is controller responsible for in MVC?

A controller is responsible for controlling the way that a user interacts with an MVC application. A controller contains the flow control logic for an ASP.NET MVC application. A controller determines what response to send back to a user when a user makes a browser request.

How does MVC know which controller to use?

This is because of conventions. The default convention is /{controller}/{action} , where the action is optional and defaults to Index . So when you request /Scott , MVC's routing will go and look for a controller named ScottController , all because of conventions.


2 Answers

In addtion to DavidG's answer.

When you publish the project the compiled build does not have a Properties folder. To solve the issue while developing locally you can set RouteExistingFiles to true so ASP.NET routing handles all requests.

public static void RegisterRoutes(RouteCollection routes)
{
       routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
       routes.RouteExistingFiles = true;

       routes.MapRoute(
           name: "Default",
           url: "{controller}/{action}/{id}",
           defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
       );
}
like image 74
tmg Avatar answered Sep 30 '22 12:09

tmg


The issue is that your project already contains a folder called Properties which is mainly used for the AssemblyInfo.cs file but has other stuff in there too. The engine used to resolve what files to send to the client prioritises files and folders over routing. so the URL http://site/properties is trying to server content from there, which is ultimately blocked anyway.

like image 37
DavidG Avatar answered Sep 30 '22 11:09

DavidG