简体   繁体   English

ASP.NET MVC 页面不会加载并显示“找不到资源”

[英]ASP.NET MVC Page Won't Load and says "The resource cannot be found"

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.描述:HTTP 404。您要查找的资源(或其依赖项之一)可能已被删除、更改名称或暂时不可用。 Please review the following URL and make sure that it is spelled correctly.请检查以下 URL 并确保其拼写正确。

Requested URL: /EventScheduler/account.aspx/login请求的 URL:/EventScheduler/account.aspx/login

Version Information: Microsoft .NET Framework Version:2.0.50727.3053;版本信息:Microsoft .NET Framework 版本:2.0.50727.3053; ASP.NET Version: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.我想我一定是忘记了一步。

I got the same error when building.我在构建时遇到了同样的错误。 The default is to use URLRoute settings for navigating.默认是使用 URLRoute 设置进行导航。 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.如果您通过右键单击任何 cshtml 页面来选择“设置为启动页面”属性,则会引发此错误,因为在 Global.asax 文件下始终存在到当前页面的路由。

Look at Project Properties for Startup Path and delete it.查看启动路径的项目属性并将其删除。

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 }

Make sure you're not telling IIS to check and see if a file exists before serving it up.确保您没有告诉 IIS 在提供文件之前检查并查看文件是否存在。 This one has bitten me a couple times.这个已经咬了我好几次了。 Do the following:请执行下列操作:

Open IIS manager.打开 IIS 管理器。 Right click on your MVC website and click properties.右键单击您的 MVC 网站,然后单击属性。 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 .在通配符应用程序映射下,确保您有一个到c:\\windows\\microsoft.net\\framework\\v2.0.50727\\aspnet_isapi.dll的映射。 MAKE SURE "Verify the file exists" IS NOT CHECKED!请确保未检查“验证文件存在”!

You should carefully review your Route Values.您应该仔细检查您的路由值。

routes.MapRoute(
   "Default", // Route name
   "{controller}/{action}/{id}", // URL with parameters
   new { controller = "Home", action = "Index", id = UrlParameter.Optional } 

In this case, ensure you have your Controller 'Home' as the application will fail to load if there is no HomeController with Index Action.在这种情况下,请确保您拥有控制器“Home”,因为如果没有带有索引操作的 HomeController,应用程序将无法加载。 In My case I had HomesController and I missed the 's' infront of the Home.在我的情况下,我有 HomesController 并且我错过了 Home 前面的“s”。 I Fixed the Name mismatch and this resolved the issue on both my local environment and on my server.我修复了名称不匹配,这解决了本地环境和服务器上的问题。

If you're running IIS 6 and above, make sure the application pool your MVC app.如果您运行的是 IIS 6 及更高版本,请确保应用程序池您的 MVC 应用程序。 is using is set to Integrated Managed Pipeline Mode.正在使用设置为集成托管管道模式。 I had mine set to Classic by mistake and the same error occurred.我错误地将我的设置为 Classic 并且发生了同样的错误。

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,请按照以下步骤操作:

  1. Right click on Controller folder, and then select Add > Controller;右键单击控制器文件夹,然后选择添加 > 控制器;
  2. Select MVC 5 Controller - Empty;选择 MVC 5 控制器 - 空;
  3. Click in Add;点击添加;
  4. Put HomeController for the controller name;将 HomeController 作为控制器名称;
  5. Build the project and after Run your project again构建项目,然后再次运行您的项目

I hope this help我希望这有帮助

有同样的问题,就我而言,原因是虚拟目录文件夹中缺少 web.config 文件。

I got the same error while building a MVC application.我在构建 MVC 应用程序时遇到了同样的错误。
In my case it happened because I forgot to add the string "Controller" in my controller name.就我而言,这是因为我忘记在控制器名称中添加字符串“Controller”。

Error With错误与

public class ProductType : BaseController
{
    public ProductType()
    {
    }
}

Resolved解决

public class ProductTypeController : BaseController
{
    public ProductTypeController ()
    {
    }
}

In your Project open Global.asax.cs then right click on Method RouteConfig.RegisterRoutes(RouteTable.Routes);在您的项目中打开 Global.asax.cs 然后右键单击 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.然后单击转到定义然后在defaults: new { controller = "Home", action = "Index", id =UrlParameter.Optional}然后将“Home”的名称更改为您自己的控制器名称,并将索引更改为您自己的视图名称,如果您已经更改了“HomeController”和“Index”以外的名称希望您的问题得到解决。


Step 1 : Check to see if you have received the following update?第 1 步:检查您是否收到以下更新? http://support.microsoft.com/kb/894670 If you have you might want to follow this procedure and see if it works for you. http://support.microsoft.com/kb/894670如果您有,您可能希望按照此步骤操作,看看它是否适合您。 It worked partially for me.它部分对我有用。 The item where it mentions the additional "/" to be removed is not entirely true but it did give me some insight to change my project properties just a bit.它提到要删除的附加“/”的项目并不完全正确,但它确实让我对更改我的项目属性有一些了解。

step 2 : Right click on your properties for your Web Project in your Solun.第 2 步:在 Solun 中右键单击您的 Web 项目的属性。 Select WEB > Choose Current Page instead of Specific Page.选择 WEB > 选择当前页面而不是特定页面。

step 3 : Go into your project where you keep your *.aspx's select a start page.第 3 步:进入您的项目,在其中保留 *.aspx 的选择起始页。 (Should be the same as the current page or choose another one of your choice :) ) Hit Debug Run. (应该与当前页面相同或选择另一个您的选择:))点击调试运行。

Two Things Needs To Be Ensure:需要确保两件事:

1) Route should be proper in Global.ascx file 1) RouteGlobal.ascx文件中应该是正确的

2) Don't forget to add reference of Controller Project in your Web Project ( view is in separate project from controller ) 2)不要忘记在您的Web Project添加Controller Project引用(视图与控制器位于不同的项目中

The second one is my case.第二个是我的情况。

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.明确单击项目文件中的“创建虚拟目录”按钮。

Go to any page you want to see it in browser right click--> view in browser.转到您想在浏览器中查看的任何页面,右键单击--> 在浏览器中查看。 this way working with me.这样和我一起工作。

Upon hours of debugging, it was just an c# error in my html view.经过数小时的调试,我的 html 视图中只是一个 c# 错误。 Check your view and track down any error检查您的视图并追踪任何错误

Don't comment c# code using html style ie不要使用 html 样式注释 c# 代码,即

Remember to use PUBLIC for ActionResult:记住对 ActionResult 使用 PUBLIC:

public ActionResult Details(int id)
{
    return View();
}

instead of代替

 ActionResult Details(int id)
 {
     return View();
 }

Open your Controller.cs file and near your public ActionResult Index() , in place of Index write the name of your page you want to run in the browser.打开您的Controller.cs文件,并在您的public ActionResult Index()附近写下您要在浏览器中运行的页面名称,而不是Index For me it was public ActionResult Login() .对我来说,它是public ActionResult Login()

you must check if you implemented the page in the controller for example:您必须检查您是否在控制器中实现了页面,例如:

   public ActionResult Register()
        {
            return View();
        } 

I had a similar problem.我有一个类似的问题。 But I was working with Episerver locally with ssl enabled.但是我在启用 ssl 的情况下在本地使用 Episerver。 When I wasn't getting a当我没有得到

Server Error in '/' Application. “/”应用程序中的服务器错误。

I was getting a Insecure connection error.我收到不安全的连接错误。 In the end, for me, this post on PluralSight together with configuring the website urls, accordingly with the ssl link set up on the project's config, on Admin's Manage Website's screen solved the problem.最后,对我来说, PluralSight上的这篇文章连同配置网站 url,相应地在项目配置上设置了 ssl 链接,在管理员的管理网站屏幕上解决了这个问题。

In my case, I needed to replace this:就我而言,我需要替换它:

@Html.ActionLink("Return license", "Licenses_Revoke", "Licenses", new { id = userLicense.Id }, null)

With this:有了这个:

<a href="#" onclick="returnLicense(event)">Return license</a>

<script type="text/javascript">
    function returnLicense(e) {
        e.preventDefault();

        $.post('@Url.Action("Licenses_Revoke", "Licenses", new { id = Model.Customer.AspNetUser.UserLicenses.First().Id })', getAntiForgery())
            .done(function (res) {
                window.location.reload();
            });
    }
</script>

Even if I don't understand why.即使我不明白为什么。 Suggestions are welcome!欢迎提出建议!

For me its solved follow the following steps :对我来说,它的解决步骤如下:

One reason for this occur is if you don't have a start page or wrong start page set under your web project's properties.发生这种情况的一个原因是,如果您在 Web 项目的属性下没有设置起始页或错误的起始页。 So do this:所以这样做:

1- Right click on your MVC project 1-右键单击您的MVC项目

2- Choose "Properties" 2-选择“属性”

3- Select the "Web" tab 3- 选择“Web”选项卡

4- Select "Specific Page" 4-选择“特定页面”

Assuming you have a controller called HomeController and an action method called Index, enter "home/index" in to the text box corresponding to the "Specific Page" radio button.假设您有一个名为 HomeController 的控制器和一个名为 Index 的操作方法,请在与“Specific Page”单选按钮对应的文本框中输入“home/index”。

Now, if you launch your web application, it will take you to the view rendered by the HomeController's Index action method.现在,如果您启动您的 Web 应用程序,它将带您到由 HomeController 的 Index 操作方法呈现的视图。

It needs you to add a Web Form, just go to add on properties -> new item -> Web Form.它需要您添加一个Web Form,只需添加属性-> 新项目-> Web Form。 Then wen you run it, it will work.然后你运行它,它会工作。 Simple简单的

I had the same problem caused by my script below.我的下面的脚本导致了同样的问题。 The problem was caused by url variable.问题是由 url 变量引起的。 When I added http://|web server name|/|application name|当我添加http://|web服务器名称|/|应用程序名称| 时in front of /Reports/ReportPage.aspx ... it started to work.在 /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>

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

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