【发布时间】:2019-04-30 07:30:13
【问题描述】:
我创建了一个名为“服务”的控制器,除了默认操作不起作用之外,它工作正常。更具体地说,当我尝试联系 .../Services 时,我得到了
HTTP 错误 403.14 - 禁止
错误但.../Services/Index 有效。所有其他控制器工作正常。我做错了什么还是有任何保留的路线或类似的东西?我已经删除了RouteConfig 中的“IgnoreRoute”,但仍然无法正常工作。
这是控制器代码:
public class ServicesController : Controller
{
private ApplicationDbContext db = new ApplicationDbContext();
// GET: Services
public ActionResult Index(int CategoryId = -1)
{
if (CategoryId == -1)
{
var services = db.Services.Include(s => s.ServiceCategory).Include( i => i.Images);
return View(services.ToList());
}
else
{
var services = db.Services.Where(r => r.ServiceCategoryId == CategoryId).Include(p => p.ServiceCategory).Include(i => i.Images);
return View(services.ToList());
}
}
}
还有路线配置:
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 }
);
}
}
编辑: 我找到了原因,我在项目的解决方案中有一个名为“服务”的文件夹。但是我认为这种行为是不可接受的,所以我的问题是解决这个问题的方法是什么?
【问题讨论】:
-
我用你拥有的东西创建了一个项目,我的意思是你的控制器,它工作正常。
-
我觉得这个链接对你有帮助:stackoverflow.com/questions/44932387/…
-
谢谢,我同时找到了原因并编辑了问题。
标签: c# asp.net-mvc routing