ASP.NET MVC Action在某些参数上给出了404?

时间:2022-11-29 14:12:15

I'm getting a strange error in my MVC site. I have an action in my controller which responds to the default route of {controller}/{action}/{id} - in my case, /Project/Client/{id}.

我的MVC网站出现了一个奇怪的错误。我的控制器中有一个操作响应{controller} / {action} / {id}的默认路由 - 在我的情况下,/ Project / Client / {id}。

Depending on the id I pass to it, I get an error. With Elmah off, it's a straight-up ASP.NET 404 error. Turning Elmah on gives me the following:

根据我传递给它的ID,我收到错误。随着Elmah关闭,这是一个直接的ASP.NET 404错误。转动Elmah给我以下内容:

System.Web.HttpException
   at System.Web.CachedPathData.GetConfigPathData(String configPath)
   at System.Web.CachedPathData.GetVirtualPathData(VirtualPath virtualPath, Boolean permitPathsOutsideApp)
   at System.Web.HttpContext.GetFilePathData()
   at System.Web.HttpContext.GetConfigurationPathData()
   at System.Web.Configuration.RuntimeConfig.GetConfig(HttpContext context)
   at System.Web.HttpContext.get_ImpersonationToken()
   at System.Web.ClientImpersonationContext.Start(HttpContext context, Boolean throwOnError)
   at System.Web.HttpApplication.ThreadContext.SetImpersonationContext()
   at System.Web.HttpApplication.ThreadContext.Enter(Boolean setImpersonationContext)
   at System.Web.HttpApplication.OnThreadEnterPrivate(Boolean setImpersonationContext)
   at System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(Exception error)

This only happens with certain ID params. for example

这只发生在某些ID参数上。例如

/Projects/Client/ABC -- works
/Projects/Client/DEF -- works
/Projects/Client/GHI -- 404
/Projects/Client/JKL -- works

and so on...

等等...

Any clues?

3 个解决方案

#1


You can use Phil Haacks route debugger to learn which routes are being called read here: http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx

你可以使用Phil Haacks路由调试器来了解这里读取的路由:http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx

#2


One thing you should look at is your web.config files in your site. The top of your stack trace;

您应该关注的一件事是您网站中的web.config文件。堆栈顶部的跟踪;

at System.Web.CachedPathData.GetConfigPathData(String configPath)

Looks to be a call to determine the location of the web.config. It may be that the virtual file system being defined by your routes (/Project/client/id) is conflicting with a web.config that may exist at, say, ~/Project/web.config

看起来是一个确定web.config位置的调用。可能是您的路由(/ Project / client / id)定义的虚拟文件系统与web.config冲突,例如〜/ Project / web.config中可能存在的web.config

It's a bit of a wild stab derived from the stack trace, but shouldn't take too long to see if it might be a problem.

这是一个源自堆栈跟踪的狂野刺,但是不应该花太长时间才能看出它是否有问题。

#3


In case anyone else shows up on this page and doesn't find the solution they are looking for, certain character strings are not allowed in URLs. Read about it here:

如果其他人出现在此页面上并且找不到他们正在寻找的解决方案,则URL中不允许使用某些字符串。在这里阅读:

Weird 404 error in ASP.NET MVC when including "con"

包含“con”时ASP.NET MVC中出现奇怪的404错误

The solution is another of Microsoft's "WorkProperly" flags (whose default value is "false")

该解决方案是Microsoft的另一个“WorkProperly”标志(其默认值为“false”)

#1


You can use Phil Haacks route debugger to learn which routes are being called read here: http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx

你可以使用Phil Haacks路由调试器来了解这里读取的路由:http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx

#2


One thing you should look at is your web.config files in your site. The top of your stack trace;

您应该关注的一件事是您网站中的web.config文件。堆栈顶部的跟踪;

at System.Web.CachedPathData.GetConfigPathData(String configPath)

Looks to be a call to determine the location of the web.config. It may be that the virtual file system being defined by your routes (/Project/client/id) is conflicting with a web.config that may exist at, say, ~/Project/web.config

看起来是一个确定web.config位置的调用。可能是您的路由(/ Project / client / id)定义的虚拟文件系统与web.config冲突,例如〜/ Project / web.config中可能存在的web.config

It's a bit of a wild stab derived from the stack trace, but shouldn't take too long to see if it might be a problem.

这是一个源自堆栈跟踪的狂野刺,但是不应该花太长时间才能看出它是否有问题。

#3


In case anyone else shows up on this page and doesn't find the solution they are looking for, certain character strings are not allowed in URLs. Read about it here:

如果其他人出现在此页面上并且找不到他们正在寻找的解决方案,则URL中不允许使用某些字符串。在这里阅读:

Weird 404 error in ASP.NET MVC when including "con"

包含“con”时ASP.NET MVC中出现奇怪的404错误

The solution is another of Microsoft's "WorkProperly" flags (whose default value is "false")

该解决方案是Microsoft的另一个“WorkProperly”标志(其默认值为“false”)