简体   繁体   English

在asp.net-mvc中找不到错误

[英]Not found error in asp.net-mvc

Every time I run a certain application it is showing a Not Found error 每次运行某个应用程序时,它都会显示Not Found错误 替代文字

Does anyone know how to resolve this? 有谁知道如何解决这个问题?

I placed a debugger on the page_load event in the default.aspx.cs file but it is not getting called. 我在default.aspx.cs文件中的page_load事件上放置了一个调试器,但它没有被调用。

Below is the routing configuration: 以下是路由配置:

 routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // parameters
            new { controller = "Home", action = "Index", id = "" }  // Parametedefaults
        );

I tried everything I can think of, but it is not working. 我尝试了所有我能想到的东西,但它没有用。

What web server are you running this on VS Dev/Cassini? 你在VS Dev / Cassini上运行这个Web服务器是什么? IIS? IIS? See if you have a default.aspx in the root folder. 查看根文件夹中是否有default.aspx。 You need a dummy root default.aspx for MVC to work properly with some webservers. 您需要一个虚拟根default.aspx,以便MVC能够与某些Web服务器一起正常工作。

If you are using IIS 6 you will need a wild card mapping to the aspnet isapi filter if you are using urls without an extension. 如果您使用的是IIS 6,则在使用没有扩展名的网址时,您需要使用通配符映射到aspnet isapi过滤器。 There are other options such as using a fake extension eg mvc and mapping through to that. 还有其他选项,例如使用虚假扩展,例如mvc和映射到那。 By default IIS 6 doesn't know to treat pages without extensions as asp.net 默认情况下,IIS 6不知道将没有扩展名的页面视为asp.net

Steve Sanderson gives an excellent article about deploying to IIS 6 ( http://blog.stevensanderson.com/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/ ). 史蒂夫桑德森提供了一篇关于部署到IIS 6的优秀文章( http://blog.stevensanderson.com/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/ )。

Of course if you are using IIS7 then it should just work out of the box. 当然,如果您使用的是IIS7,那么它应该只是开箱即用。 In that case I don't know. 在那种情况下,我不知道。

If you have all the things in their places then it seems like either: 如果你拥有他们所有的东西,那么它似乎是:

  • The routes are configured incorrectly. 路由配置错误。 Most likely you don't have proper default values for your Controller/Action . 很可能您的Controller/Action没有正确的默认值。
  • You are using older IIS versions and they're not configured properly. 您使用的是较旧的IIS版本,但未正确配置。 See this for instructions. 请参阅说明。

Try to check your Default.aspx code as below: 尝试检查Default.aspx代码如下:

using System.Web;
using System.Web.Mvc;
using System.Web.UI;

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, System.EventArgs e)
    {
        HttpContext.Current.RewritePath(Request.ApplicationPath, false);
        IHttpHandler httpHandler = new MvcHttpHandler();
        httpHandler.ProcessRequest(HttpContext.Current);
    }
}

and you need to configure your iis's wildcard mapping, see below: http://weblogs.asp.net/scottgu/archive/2007/03/04/tip-trick-integrating-asp-net-security-with-classic-asp-and-non-asp-net-urls.aspx 并且您需要配置iis的通配符映射,请参阅以下内容: http//weblogs.asp.net/scottgu/archive/2007/03/04/tip-trick-integrating-asp-net-security-with-classic-asp -and-非ASP净urls.aspx

From the looks of it you don't have a default route set up. 从它的外观来看,你没有设置默认路线。 Try this: 尝试这个:

Routes.MapRoute("Site (*)", "{action}", new {
    controller = "Site",
    action = "Default"
});

This basically sets up a root route which defaults the action to "Default" if nothing is passed in. This also maps to all root routes such as /Home , /Contact , /{Whatever} . 这基本上设置了一个根路由,如果没有传入任何内容,则将该操作默认为“Default”。这也会映射到所有根路由,例如/Home/Contact/{Whatever}

as per comments in question I placed debugger on page_load event in default.aspx.cs file but it is not getting called. 根据有问题的评论, 我将调试器放在default.aspx.cs文件中的page_load事件上,但它没有被调用。 Below is the routing configuration: 以下是路由配置:

  • have you tried to set your default.aspx as StartUp Page for your project. 您是否尝试将default.aspx设置为项目的StartUp Page。

and same in IIS virtual directory. 和IIS虚拟目录中相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM