I created a new ASP.NET MVC 2 Empty Web Application. I didn't add any line of code to it. I simply ran the application by pressing F5 .The browser opens and I get an error message stating that
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.
What is the problem?
By default the empty project doesn't have any controller defined in it.
So first add it and then run it.
I have created MVC2 web application.
Account controller and Home controller is available by default and run the application is does not get any error.
And second time i have created MVC2 Empty web Application .
None of controller,views and model are present in this project.After this i simply run application and i got same error as you say.Yes this error will come because none of controller,view and model is not present.So first try to make MVC2 Web application
and second time try to make MVC2 Empty web application
and add one controller ,view and model
Steps are below:
1)First make on model name as City under Model Folder for example:City.cs
2)Then make one Folder under View folder name as City
3)Make one view under City folder name as Index
4)Make one controller under Controller folder name as CityController.cs
5)Bydefault Index method is present in citycontroller so no need to make it.
6)After this run the application with browser url is localhost://City/Index
Related
i have a problem with my application created in umbraco.
I have implemented the application on microsoft azure and I wanted to edit one function in the controller using kudu. I have edited the controller file, but the changes have not been made in the application (as I will go to the site is the state from before editing). I have combined a bit how to get the desired effect, I even deleted the controller file and it is still the same (state from before. Can you write to me how to correctly edit the controller file?
A project kind of landed on my hands and I am having issues with one thing.
I have an already working project that is installed on a local server. I am able to make changes to existing pages, but I just tried creating a new page from copying an existing page and modifying it, but I keep getting an error when I try to open it. This is the error:
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.
From my research so far, it looks like there has to be a controller in place to properly map the new pages, but I have not been able to find that within the project. I copied the project and opened it with ms visual on a different machine, same issue, everything opens and works just fine except the new page that I added. While the project is open on ms visual I do not see a folder for controllers either.
I would greatly appreciated if someone can point me on the right direction
Thank you,
Cesar R
With Model/View/Controller, you need a Controller to match with the View.
Let's say you add a new folder and cshtml to your file in the following folder:
~/Views/Test/Test.cshtml
You also need a controller named similarly in the following folder:
~/Controllers/TestController.cs
and inside that controller you need a method that matches the name of the view:
public ActionResult Test()
{
return View();
}
That will make http://[yourwebsiteurl]/Test/Test be an active page.
by mistake i set Home => Index set as start page. but now when i run the project it gives following error
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: /Views/Home/Index.cshtml
when i remove /Views/Home/Index.cshtml from url it runs correctly. So every time i have to remove /Views/Home/Index.cshtml from url.
How to undo that settings???
By requesting /Views/Home/Index.cshtml you are trying to get the content of Index.cshtml file which is blocked in Web.config in your views folder.
The correct URL for Index action in Home Controller is Home/Index
By the way, one of the most common reasons for your issue is when you try to run/debug your project from visual studio and you selected some specific cshtml file (In your case, you most probably try tor run the project while you are working on Index.cshtml file )
I've created a copy(right-click Copy & Paste) of my Home page in a VS2013 ASP.NET MVC5 project and named it indexL10. When I try to run it, I get the following error:
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: /Home/IndexL10
So, I'm guessing there's more to it than copying and pasting. I've tried googling around, but I've not found an answer, or search string that takes me to a page of a user with a similar problem.
Does anyone have any ideas/suggestions? Thanks
*.cshtml files are not like *.aspx files. They're not directly exposed. The URL is translated by the framework into a route. That route points to a particular controller and a particular action in that controller, which is then called by the framework. The action returns an ActionResult, which in MVC is most typically satisfied via a ViewResult. Conventions in the framework come into play to look for a view to render with the same name as the action that was called, but this is not strictly required and can be overridden. Regardless, the view (your *.cshtml file) is rendered by Razor utilizing data provided by the action and returned as a response to the client.
In a common ASP.NET Web Forms page, I specify the location of a backup file as follows:
string backupFilePath = "../data/backups";
ICronjobTask[] tasks = new ICronjobTask[]
{
new FileBackupCronjobTask(backupFilePath)
};
The ICronjobTask is executed later on. When calling the published page on my web server, an error message tells me that parts of the path "C:\Windows\SysWOW64\inetsrv\data\backups\file.txt could not be found.
Why does ASP.NET publish my local directory structure? How do I turn this off?
You're displaying the raw exception error message, is my guess. Whenever you do that, you risk giving away information that you don't want to be made public. Instead of doing that, you should interpret the exception and give general information to the user.
The solution was to use the Server.MapPath(string path) method that returns the physical path corresponding to the specified logical one.