C# ASP.NET MVC 页面不会加载并显示“找不到资源”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/893552/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ASP.NET MVC Page Won't Load and says "The resource cannot be found"
提问by skb
I am having a problem where I try to open my ASP.NET MVC application but I get the ASP.NET error page which says this:
我在尝试打开 ASP.NET MVC 应用程序时遇到问题,但出现了 ASP.NET 错误页面,其中显示:
Server Error in '/' Application.
The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /EventScheduler/account.aspx/login
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053**
“/”应用程序中的服务器错误。
无法找到该资源。描述:HTTP 404。您要查找的资源(或其依赖项之一)可能已被删除、更改名称或暂时不可用。请检查以下 URL 并确保其拼写正确。
请求的 URL:/EventScheduler/account.aspx/login
版本信息:Microsoft .NET Framework 版本:2.0.50727.3053;ASP.NET 版本:2.0.50727.3053**
I am using the URL trick from this blog post and that is why I have the .aspx in the URL:
我正在使用这篇博客文章中的 URL 技巧,这就是为什么我在 URL 中有 .aspx 的原因:
http://blog.codeville.net/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/
http://blog.codeville.net/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/
It works on my other sandbox server (not a dev machine), and now I just deployed it to my production site as a new virtual directory, but for some reason it seems like it's actually looking for a .aspx file.
它适用于我的其他沙箱服务器(不是开发机器),现在我只是将它作为新的虚拟目录部署到我的生产站点,但由于某种原因,它似乎实际上是在寻找 .aspx 文件。
Any ideas? I think I must be forgetting a step.
有任何想法吗?我想我一定是忘记了一步。
回答by skb
Make sure you're not telling IIS to check and see if a file exists before serving it up. This one has bitten me a couple times. Do the following:
确保您没有告诉 IIS 在提供文件之前检查并查看文件是否存在。这个已经咬了我好几次了。请执行下列操作:
Open IIS manager. Right click on your MVC website and click properties. Open the Virtual Directory tab. Click the Configuration... button. Under Wildcard application maps, make sure you have a mapping to c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll
. MAKE SURE "Verify the file exists" IS NOT CHECKED!
打开 IIS 管理器。右键单击您的 MVC 网站,然后单击属性。打开虚拟目录选项卡。单击配置...按钮。在通配符应用程序映射下,确保您有一个到c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll
. 请确保未检查“验证文件存在”!
回答by Igor Brejc
If you're running IIS 6 and above, make sure the application pool your MVC app. is using is set to IntegratedManaged Pipeline Mode. I had mine set to Classic by mistake and the same error occurred.
如果您运行的是 IIS 6 及更高版本,请确保应用程序池您的 MVC 应用程序。正在使用设置为集成托管管道模式。我错误地将我的设置为 Classic 并且发生了同样的错误。
回答by gabouy
Had the same issue, in my case the cause was that the web.config file was missing in the virtual dir folder.
有同样的问题,就我而言,原因是虚拟目录文件夹中缺少 web.config 文件。
回答by dewelloper
I got the same error when building. The default is to use URLRoute settings for navigating. If you select the "Set as Startup Page" property by right clicking any cshtml page, that throws this error because there are always a routing to the current page under the Global.asax file.
我在构建时遇到了同样的错误。默认是使用 URLRoute 设置进行导航。如果通过右键单击任何 cshtml 页面来选择“设置为启动页面”属性,则会引发此错误,因为在 Global.asax 文件下始终存在到当前页面的路由。
Look at Project Properties for Startup Path and delete it.
查看启动路径的项目属性并将其删除。
回答by AleckxGhost
I found the solution for this problem, you don't have to delete the global.asax, as it contains some valuable info for your proyect to run smoothly, instead have a look at your controller's name, in my case, my controller was named something as MyController.cs and in the global.asax it's trying to reference a Home Controller.
我找到了这个问题的解决方案,你不必删除 global.asax,因为它包含一些有价值的信息,让你的项目顺利运行,而是查看你的控制器名称,在我的情况下,我的控制器被命名MyController.cs 和 global.asax 它试图引用一个家庭控制器。
Look for this lines in the global asax
在全局 asax 中查找此行
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
in my case i had to get like this to work
就我而言,我必须像这样工作
new { controller = "My", action = "Index", id = UrlParameter.Optional }
回答by CodeFarmer
Suppose source code copy from other places.
假设从其他地方复制源代码。
Sometime, if you use Virtual Directory in your application url like:
有时,如果您在应用程序 url 中使用虚拟目录,例如:
http://localhost:50385/myapp/#/
No route will pick up the request.
没有路由会接收请求。
solution:
解决方案:
Explicitly click the button 'create a virtual directory' in your project file.
明确单击项目文件中的“创建虚拟目录”按钮。
回答by Victor Jatobá
The page is not found cause the associated controller doesn't exit. Just create the specific Controller. If you try to show the home page, and use Visual Studio 2015, follow this steps:
找不到页面,因为关联的控制器没有退出。只需创建特定的控制器。如果您尝试显示主页并使用 Visual Studio 2015,请按照以下步骤操作:
- Right click on Controller folder, and then select Add > Controller;
- Select MVC 5 Controller - Empty;
- Click in Add;
- Put HomeController for the controller name;
- Build the project and after Run your project again
- 右键单击控制器文件夹,然后选择添加 > 控制器;
- 选择 MVC 5 控制器 - 空;
- 点击添加;
- 将 HomeController 作为控制器名称;
- 构建项目,然后再次运行您的项目
I hope this help
我希望这有帮助
回答by Kedar9444
I got the same error while building a MVC application.
In my case it happened because I forgot to add the string "Controller" in my controller name.
我在构建 MVC 应用程序时遇到了同样的错误。
就我而言,这是因为我忘记在控制器名称中添加字符串“Controller”。
Error With
错误与
public class ProductType : BaseController
{
public ProductType()
{
}
}
Resolved
解决
public class ProductTypeController : BaseController
{
public ProductTypeController ()
{
}
}
回答by Azmat Ullah
In your Project open Global.asax.cs then right click on Method RouteConfig.RegisterRoutes(RouteTable.Routes); then click Go To Definition
then at defaults: new { controller = "Home", action = "Index", id =UrlParameter.Optional}
then change then Names of "Home" to your own controller Name and Index to your own View Name if you have changed the Names other then "HomeController" and "Index"
Hope your Problem will be Solved.
在您的项目中打开 Global.asax.cs 然后右键单击 Method RouteConfig.RegisterRoutes(RouteTable.Routes); 然后单击转到定义,defaults: new { controller = "Home", action = "Index", id =UrlParameter.Optional}
然后将“Home”的名称更改为您自己的控制器名称,并将索引更改为您自己的视图名称,如果您更改了“HomeController”和“Index”以外的名称,希望您的问题得到解决。
回答by ZagorTeNej
I had the same problem caused by my script below. The problem was caused by url variable. When I added http://|webserver name|/|application name| in front of /Reports/ReportPage.aspx ... it started to work.
我的下面的脚本导致了同样的问题。问题是由 url 变量引起的。当我添加http://|web服务器名称|/|应用程序名称| 时 在 /Reports/ReportPage.aspx 前面......它开始工作了。
<script>
$(document).ready(function () {
DisplayReport();
});
function DisplayReport() {
var url = '/Reports/ReportPage.aspx?ReportName=AssignmentReport';
if (url === '')
return;
var myFrame = document.getElementById('frmReportViewer');
if (myFrame !== null) {
if (myFrame.contentWindow !== null && myFrame.contentWindow.location !== null) {
myFrame.contentWindow.location = url;
}
else {
myFrame.setAttribute('src', url);
}
}
}
</script>