简体   繁体   English

.aspx页不在MVC5应用程序的根目录时导致“ 404 not found”

[英].aspx page causes “404 not found” when not in root of an MVC5 app

Ok, this one has me stumped, been at it all day. 好吧,这让我难过了,整日忙着。 I have an MVC5 app that can't find an .aspx page in a subfolder. 我有一个MVC5应用程序,在子文件夹中找不到.aspx页。

So I have an .aspx page here /Reports/page.aspx 所以我在这里有一个.aspx页面/Reports/page.aspx

and i've tried adding each of these route config additions based on various web searches 我已经尝试根据各种网络搜索添加这些路由配置添加项

routes.Ignore("{resource}.aspx/{*pathinfo}");
routes.Ignore("Reports/{resource}.aspx/{*pathInfo}");
routes.IgnoreRoute("Reports/{*allaspx}", new { allaspx = @".*\.aspx(/.*)?" });

The problem i'm finding is that an .aspx file in the root of the site is found, but not my .aspx in the 'Reports' subfolder. 我发现的问题是在网站根目录中找到了一个.aspx文件,但在“报告”子文件夹中却找不到我的.aspx文件。

Even stranger, I can publish locally and point my local IIS7.5 at my published site and it routes to my .aspx files fine. 甚至更陌生的是,我可以在本地发布并将本地IIS7.5指向发布的站点,并且可以路由到我的.aspx文件。 Publishing to a remote server (shared hosting) I get 404's! 发布到远程服务器(共享主机),我得到404!

If anybody has any clue as to what might be the cause...an IIS config setting perhaps? 如果有人对可能的原因有任何线索...也许是IIS配置设置? ... i'd appreciate any help. ...我将不胜感激。 I've literally googled ALL day and found nothing that's sorted it. 我从字面上搜索了一整天,没有发现排序的任何东西。

Thanks in advance... 提前致谢...

Registering routes.Ignore and routes.IgnoreRoute is not required. 注册路由。忽略和路由.IgnoreRoute不是必需的。 aspx should work fine (and it seems it works within the root). aspx应该可以正常工作(似乎可以在根目录下工作)。 Are you sure that there is no any rewriting rule or other route which is related to the /Reports folder? 您确定没有任何与/ Reports文件夹相关的重写规则或其他路由吗? Is that happen to all folders? 这是否发生在所有文件夹上? Try to create an empty aspx file or just put <%= Now %> and see if it works with other name or other folder. 尝试创建一个空的aspx文件,或只放置<%= Now%>并查看它是否可以与其他名称或其他文件夹一起使用。

As smirnov mentioned in the comment, none of the routes.Ignore or routes.IgnoreRoute statements are needed for accessing .aspx files. 正如评论中smirnov所提到的,访问.aspx文件都不需要route.Ignore或route.IgnoreRoute语句。 However, you could be facing an issue that I also faced recently. 但是,您可能会遇到我最近也遇到的一个问题。 So, I'll mention the scenario. 因此,我将介绍这种情况。

If you are using "Web.sitemap" file and you have entry for "filename.aspx" only, you'd face runtime errors accessing the sitemap entry for that page. 如果您使用的是“ Web.sitemap”文件,并且仅具有“ filename.aspx”条目,则在访问该页面的站点地图条目时会遇到运行时错误。 The reason is, the MVC framework converts "/abc.aspx" request to "/abc". 原因是,MVC框架将“ /abc.aspx”请求转换为“ / abc”。 So, I had to use duplicate entries in the web.sitemap as following: 因此,我不得不在web.sitemap中使用重复项,如下所示:

<siteMapNode url="Account/AddUser.aspx" title="Add New User"  description="">
</siteMapNode>

<siteMapNode url="Account/AddUser" title="Add New User"  description="">
</siteMapNode>

Of course, some elegant solution like "Routes.Ignore()" must be out there, but, my point is absence of those is not the reason of the inaccessibility of .aspx files. 当然,必须有一些优雅的解决方案,例如“ Routes.Ignore()”,但是,我要指出的是,缺少这些不是.aspx文件不可访问的原因。

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

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