简体   繁体   中英

cshtml files not serving from subdirectory

First off, I apologise if this question has actually been answered previously, but I cannot find a valid response.

I have created a very basic web SITE in Visual Studio 2013, not an application or MVC or anything like that.

The default file is default.cshtml

1) When I run in debug mode, no problem
2) When I publish to my IIS 7 server's wwwroot folder, http://webserver/default.cshtml works
3) When I publish to a subfolder of wwwroot, http://webserver/folder/default.cshtml gives a "This type of page is not served." error message

I know the server CAN successfully serve up the .cshtml type files do to #2 above.

So what am I missing that it will not serve up .cshtml from a subdirectory?

cshtml files are served up by MVC routing, not by direct URL referencing. IIS does not know what to do with a cshtml file.

Basically you can only use that file type in a routed web app and not a basic website.

In MVC the URL would be http://webserver/somecontroller or http://webserver/ and the routing would choose which cshtml files to run and output.

The actual cshtml file rendered is selected implicitly based on the controller name, the action name (method run on the controller), what the action returns, and also any route mappings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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