c# - MVC Controller 有什么特别之处称为属性吗?

标签 c# asp.net-mvc controller asp.net-mvc-5 asp.net-mvc-routing

在尝试解决这个问题很长时间后,考虑到路由冲突等问题 - 我从头开始了一个单独的项目。

当您尝试访问根站点 (http://site/properties) 时,名为“properties”的 MVC Controller 看起来总是返回 403.14 禁止消息 - 然而,其他页面有效( http://site/properties/index).

它在一个区域中作为 Controller 工作得很好,但是,我无法在主站点中创建它。

我想知道是否有人知道为什么以及最好的解决方法是什么?

最佳答案

除了 DavidG 的 answer .

当您发布项目时,编译后的版本没有 Properties 文件夹。要在本地开发时解决此问题,您可以将 RouteExistingFiles 设置为 true,以便 ASP.NET 路由处理所有请求。

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

关于c# - MVC Controller 有什么特别之处称为属性吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34263788/

相关文章:

c# - 如何从 BitmapImage 获取 BitmapSource?

c# - 作为 WebService 使用的 WCF 添加了一个 bool 参数?

html - Bootstrap Select 在 Chrome 中显示不正确

asp.net-mvc - 阻止 bingbot 抓取我的网站

c# - 如何使用HashSet作为数学集合?

c# - 创建 Windows 服务时 SchedularCallBack 出错

c# - 用户界面中的 OWIN Web API 授权

java - 获取将您重定向到此处的页面,Spring MVC

asp.net-mvc - 在每个请求上调用 Controller 构造函数

c# - Web API 2.2,具有路由覆盖的继承 Controller (这可能吗)?