首页 > 解决方案 > 使用 ASP.NET MVC 和 IIS 10 浏览网站时出现错误 404

问题描述

我目前正在使用 ASP.NET MVC 创建一个网站。我在一个页面中有多个链接,但它们都不起作用,它们都返回 404 错误。问题是页面确实存在,并且控制器中的操作也存在。以下是错误页面上给出的详细错误信息:

Detailed Error Information:
Module: IIS Web Core
Notification: MapRequestHandler
Handler: StaticFile
Error Code: 0x80070002
Requested URL: http://localhost:80/Monitoring/CheckStatusTaskenvironnementId=1&serviceId=4&taskId=2
Physical Path: C:\ProjectsTfs\idkids\Sprint16\IdKids.Batchs\LifeTest\Monitoring\CheckStatusTask
Logon Method: Anonymous
Logon User: Anonymous

编辑:上一个操作不应该返回视图,我尝试了另一个应该返回视图的操作,但仍然是 404 错误。详细的错误信息如下:

Detailed Error Information:
Module: IIS Web Core
Notification: MapRequestHandler
Handler: StaticFile
Error Code: 0x80070002
Requested URL: http://localhost:80/Monitoring/ViewHistory?environnementId=1&serviceId=1&taskId=1
Physical Path:  C:\ProjectsTfs\idkids\Sprint-16\IdKids.Batchs\LifeTest\Monitoring\ViewHistory
Logon Method: Anonymous
Logon User: Anonymous

正如所建议的,这是在控制器中处理此操作的代码:

public ActionResult ViewHistory(int environnementId, int serviceId, int taskId)
{
    var model = _batchLogBusiness.GetTaskLog(environnementId,serviceId, taskId, false);
    return View(model);
}

这是RouteConfig课程:

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 = "Monitoring", action = "Index", id = UrlParameter.Optional }
        );
    }
} 

标签: c#asp.net-mvciis-10

解决方案


更新:我试图访问http://localhost:80/Monitoring/ViewHistory但控制器位于C:\ProjectsTfs\idkids\Sprint-16\IdKids.Batchs\LifeTest\Monitoring\ViewHistory. 当尝试访问http://localhost:80/lifetest/Monitoring/ViewHistory(使用适当的参数)时,一切正常。


推荐阅读