37

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:

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**

I am using the URL trick from this blog post and that is why I have the .aspx in the URL:

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.

Any ideas? I think I must be forgetting a step.

ArunPratap
  • 4,816
  • 7
  • 25
  • 43
skb
  • 30,624
  • 33
  • 94
  • 146

22 Answers22

18

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.

Look at Project Properties for Startup Path and delete it.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
dewelloper
  • 189
  • 1
  • 2
15

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.

Look for this lines in the global 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 }
Dale K
  • 25,246
  • 15
  • 42
  • 71
AleckxGhost
  • 151
  • 1
  • 2
7

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:

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!

  • 2
    Yes, it does. Minimum character lengths suck. –  May 21 '09 at 15:46
  • 2
    I tried this, and the Windcard application map was not there. I added, making sure to UNCHECK the "Verify the file exists" checkbox, but I am still getting the same problem. – skb May 21 '09 at 15:49
  • 1
    It wasn't there? Sounds like you need to do some work configuring IIS. Unfortunately, it can be a pain in the ass. I'd suggest you go back to tutorials for configuring IIS for MVC and follow them step by step. The issue is outside of MVC; if it wasn't, you'd be getting an error about being unable to find the route or some other yellow screen of death. –  May 21 '09 at 19:59
  • 1
    When I right-click a site I have basic settings, or advanced settings, no "properties". Couldn't find it. Where should I look? (IIS 7.5) – JNF Nov 07 '13 at 05:00
  • @JNF: This answer is for 6, not 7. You don't normally have to do *anything* in 7 to support extensionless paths. It's most likely a configuration issue. Ask about it on serverfault. Or, more likely, remove the role, then use http://www.microsoft.com/web/downloads/platform.aspx to install everything properly. Shitty server config is a nightmare to detangle. –  Nov 07 '13 at 13:17
  • @Will, apparently even 7 has it's issues. I finally found what I needed (yes, configuration) here: http://stackoverflow.com/a/17719424/1305911 – JNF Nov 10 '13 at 10:31
5

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. In My case I had HomesController and I missed the 's' infront of the Home. I Fixed the Name mismatch and this resolved the issue on both my local environment and on my server.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Kenneth O'kwu
  • 429
  • 5
  • 6
4

If you're running IIS 6 and above, make sure the application pool your MVC app. is using is set to Integrated Managed Pipeline Mode. I had mine set to Classic by mistake and the same error occurred.

Igor Brejc
  • 18,714
  • 13
  • 76
  • 95
  • 6
    do you mean IIS7 and above. I can't find anywhere in IIS 6.0 to choose Classic or Integrated Managed Pipeline modes. – modernzombie Oct 16 '09 at 12:29
3

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:

  1. Right click on Controller folder, and then select Add > Controller;
  2. Select MVC 5 Controller - Empty;
  3. Click in Add;
  4. Put HomeController for the controller name;
  5. Build the project and after Run your project again

I hope this help

Victor Jatobá
  • 811
  • 7
  • 13
2

Two Things Needs To Be Ensure:

1) Route should be proper in Global.ascx file

2) Don't forget to add reference of Controller Project in your Web Project (view is in separate project from controller)

The second one is my case.

Dale K
  • 25,246
  • 15
  • 42
  • 71
cracker
  • 4,900
  • 3
  • 23
  • 41
1

Had the same issue, in my case the cause was that the web.config file was missing in the virtual dir folder.

gabouy
  • 755
  • 1
  • 7
  • 16
  • can u articulate? I am having the same problem – JohnIdol Jan 08 '11 at 12:57
  • The web.config file had not been copied when the app was published in the IIS and that generated the "resource cannot be found error", which if you think of the message, makes sense. – gabouy Jan 31 '11 at 01:01
1

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.

Error With

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

Resolved

public class ProductTypeController : BaseController
{
    public ProductTypeController ()
    {
    }
}
Community
  • 1
  • 1
Kedar9444
  • 1,745
  • 1
  • 11
  • 15
1

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.

1


Step 1 : Check to see if you have received the following update? http://support.microsoft.com/kb/894670 If you have you might want to follow this procedure and see if it works for you. 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. Select WEB > Choose Current Page instead of Specific Page.

step 3 : Go into your project where you keep your *.aspx's select a start page. (Should be the same as the current page or choose another one of your choice :) ) Hit Debug Run.

Taja_100
  • 453
  • 6
  • 15
  • For me it was just step 2. I had right clicked on a .cshtml page and selected "set as startup" as mentioned by Dewelloper, which throws an error (I don't know why, must be a bug in Visual Studio). Thank you! – SendETHToThisAddress Oct 21 '20 at 03:19
0

Suppose source code copy from other places.

Sometime, if you use Virtual Directory in your application url like:

http://localhost:50385/myapp/#/

No route will pick up the request.

solution:

Explicitly click the button 'create a virtual directory' in your project file.

CodeFarmer
  • 2,644
  • 1
  • 23
  • 32
0

Go to any page you want to see it in browser right click--> view in browser. this way working with me.

Rawan
  • 41
  • 1
  • 9
0

Upon hours of debugging, it was just an c# error in my html view. Check your view and track down any error

Don't comment c# code using html style ie

0

Remember to use PUBLIC for ActionResult:

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

instead of

 ActionResult Details(int id)
 {
     return View();
 }
Dale K
  • 25,246
  • 15
  • 42
  • 71
alexey
  • 783
  • 1
  • 7
  • 19
0

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. For me it was public ActionResult Login().

Dale K
  • 25,246
  • 15
  • 42
  • 71
0

you must check if you implemented the page in the controller for example:

   public ActionResult Register()
        {
            return View();
        } 
حصه
  • 1
  • 1
  • 2
0

I had a similar problem. But I was working with Episerver locally with ssl enabled. 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.

Fernando Wolff
  • 216
  • 3
  • 6
0

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!

abenci
  • 8,422
  • 19
  • 69
  • 134
0

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. So do this:

1- Right click on your MVC project

2- Choose "Properties"

3- Select the "Web" tab

4- Select "Specific Page"

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.

Now, if you launch your web application, it will take you to the view rendered by the HomeController's Index action method.

Abdullah
  • 983
  • 12
  • 26
0

It needs you to add a Web Form, just go to add on properties -> new item -> Web Form. Then wen you run it, it will work. Simple

-1

I had the same problem caused by my script below. The problem was caused by url variable. When I added http://|web server name|/|application name| in front of /Reports/ReportPage.aspx ... it started to work.

<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>
  • If the solution you're proposing is to _add_ the server/application name to the start of the URL, then your code snippet is wrong and misleading. – Scott Perham Sep 15 '16 at 17:44
  • OK agree. This is what I did on controller side: public class ReportsController : Controller { public ActionResult Index(string ReportName) { int i = Request.Url.AbsoluteUri.IndexOf("/Admin/Reports"); string reportUri = Request.Url.AbsoluteUri.Substring(0, i); reportUri += "/Reports/ReportPage.aspx?ReportName=" + ReportName; return View((object) reportUri); } } and view side: @model string function DisplayReport() { var url = '@Model'; if (url === '') return; – ZagorTeNej Jun 26 '17 at 17:14