简体   繁体   English

不在子目录中的cshtml文件

[英]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. 我在Visual Studio 2013中创建了一个非常基本的网站,而不是应用程序或MVC或类似的网站。

The default file is default.cshtml 默认文件为default.cshtml

1) When I run in debug mode, no problem 1)当我在调试模式下运行时,没问题
2) When I publish to my IIS 7 server's wwwroot folder, http://webserver/default.cshtml works 2)当我发布到IIS 7服务器的wwwroot文件夹时, http://webserver/default.cshtml起作用
3) When I publish to a subfolder of wwwroot, http://webserver/folder/default.cshtml gives a "This type of page is not served." 3)当我发布到wwwroot的子文件夹时, http://webserver/folder/default.cshtml给出了“不提供此类页面”。 error message 错误信息

I know the server CAN successfully serve up the .cshtml type files do to #2 above. 我知道服务器可以成功地将.cshtml类型文件提供给上述#2。

So what am I missing that it will not serve up .cshtml from a subdirectory? 所以我想念它不会从子目录中提供.cshtml吗?

cshtml files are served up by MVC routing, not by direct URL referencing. cshtml文件由MVC路由提供,而不是由直接URL引用提供。 IIS does not know what to do with a cshtml file. IIS不知道如何处理cshtml文件。

Basically you can only use that file type in a routed web app and not a basic website. 基本上,您只能在路由的Web应用程序中使用该文件类型,而不能在基本网站中使用。

In MVC the URL would be http://webserver/somecontroller or http://webserver/ and the routing would choose which cshtml files to run and output. 在MVC中,URL为http://webserver/somecontrollerhttp://webserver/ ,路由将选择要运行和输出的cshtml文件。

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. 根据控制器名称,操作名称(在控制器上运行的方法),操作返回的内容以及任何路由映射,隐式选择渲染的实际cshtml文件。

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

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