ASP.NET MVC路由问题? [英] ASP.NET MVC routing issue?

查看:77
本文介绍了ASP.NET MVC路由问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

页面刷新后,我不断收到类似的错误消息。

I keep getting errors like this after my pages are done refreshing.

找不到路径'/S43G/S4_Manager/WebResource.axd'的控制器,或者它不会实现IController。

The controller for path '/S43G/S4_Manager/WebResource.axd' could not be found or it does not implement IController.

但我得到了硬盘驱动器上不存在的任何文件的错误。不管扩展名
(.png,.css等)

but I get the error for any file that does not exist on my hard drive. regardless of extension (.png, .css, etc)

我都尝试了以下所有方法来修复它,但我很困惑。 / p>

I've tried all of the following to fix it, and I'm stumped.

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute( "{resource}.axd" );
routes.IgnoreRoute( "WebResource.axd" );

routes.MapRoute(
"Default",                                              // Route name
"{controller}/{action}/{id}",                           // URL with parameters
new { controller = "Home", action = "Index", id = "" },  // Parameter defaults
new { controller = @"[^\.]*" }
            );

任何想法我需要在路由中添加什么,以防止每次
都引发异常文件不存在。

Any ideas what I need to put in my routing to prevent it throwing exceptions everytime a file does not exists.

除非我不应该解决这些问题,否则应该解决WebResoruce.axd问题。

barring those how to I fix the WebResoruce.axd issue, since WebResoruce.axd not supposed to exist.

谢谢

Eric =

推荐答案

我认为我的回答此处为您的问题提供了解决方案,只需匹配所有网址,并使用约束条件检查文件类型是否为.axd。

I think my answer here gives a solution to your problem, simply match all urls and use a constraint to check if the filetype is .axd.

然后,您需要执行以下操作来处理所有其他MapRoutes()之后的404请求:

Then all you need is the following to handle 404 requests after all other MapRoutes():

 routes.MapRoute(
           "Error404CatchAll", // Route name  
           "{*url}", // URL with parameters
           new { controller = "Error", action = "Http404" } // Parameter defaults
           );

这篇关于ASP.NET MVC路由问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆