Running a copy of a .cshtml file gives a 404 - asp.net

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.

Related

Razor Project on with CSHTML files

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.

In asp.net mvc by mistake i set Home => Index set as start 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 )

The resource cannot be found

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

Precalculate ASP.NET Embedded WebRessource Url

I have the following Problem.
In an Assembly, there are Resources which are exported via "WebRessource" Attribute
Ok. I know that the through the Method GetWebRessourceUrl, I can find out the Ressource Url but this happens basically at Runtime.
I need this Resource Url at Compiletime.
Why?
Because I have a Javascript which calls some of the the WebRessource Urls.
The Tricky Part is, this Javascript is also in a assembly embedded (The same Assembly as the other Resources) and is Generated and embedded at compile Time with the other Ressources.
I am grateful for every help.

Culture name is not supported

I'm receiving "culture name 'uploads' is not supported" when my ASP.NET application start. Where do I have to view/debug to toggle the error?
A full-text search for "uploads" returns 0 entries in my project.
I've deleted this folder and it solved the problem:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\8dfb04ef\44bf70fb\uploads
Do not worry, it is not a real error.
When the runtime tries to find which resource assemblies exists, it tries to enumerate folders where compiled DLL files reside. It assumes the name of the folder is the culture name, so it tries to create a culture for it. Unfortunately uploads is a folder which is created automatically by ASP.NET, and it is obviously not a culture :).
The runtime ignores some predefined folders like "hash", but not "uploads". So we have to live with it.
I am getting the exact same error. ["culture name 'uploads' is not supported"]. I do not know what is causing it but I've been able to get around it by clicking [Debug|Exceptions (Ctrl-alt-E) and un-checking "Common Language Runtime Exceptions". I do not have an 'uploads' folder or file in my project and there is nothing in my project that has anything to do with multilingual support and the error fires right off the bat when I run my project ... looking at the call stack just walks me through a whole lot of mscorlib calls. I have no clue why it's even getting called.
JumpingLethalRampage, instead of unchecking all "Commong Language Runtime Exceptions," you could uncheck just "Common Language Runtime Exceptions > System > System.ArgumentException." You don't need to uncheck all CLR items.
It sounds like maybe you have some code somewhere that is trying to set the culture based on a URL pattern (this may be tracked down if it is possible to get a stack trace). For example, sometimes I'll set up multi-lingual sites with URLs like this:
http://www.example.com/en-US/
http://www.example.com/es-MX/
I'll then have code in my base page that looks at the URL and attempts to set the culture based on the URL path. But if you tried to hit a URL like:
http://www.example.com/uploads
It would fail with an error like what you are seeing if you just blindly take the first path element and try to use it as the culture without checking it first.
If the application is it built upon DotNetNuke (and not a simple ASP.NET application), this kind of error generally occurs in DotNetNuke due to the issue described in Culture name '__page' is not supported.
If you are not using DotNetNuke, check your Application_Start code (in the Global.asax file). It might be setting the CultureInfo. Or check your web.config file for any invalid culture values.
Assuming that your search through the project wasn't restrictive (widest possible search in all files), then my guess would be that your browser has a User language set to a custom string - "uploads".
In IE, you can check via Tools -> Options -> Languages -> Add -> User defined language.

Resources