如何为 Intranet 预编译 MVC?

Posted

技术标签:

【中文标题】如何为 Intranet 预编译 MVC?【英文标题】:How to precompile MVC for intranet? 【发布时间】:2014-09-17 19:51:51 【问题描述】:

VS2013 Update3、.Net 4.5、MVC、IIS 7

我创建了一个新的 mvc 项目。 从 VS 测试,它的工作原理。 在 IIs 中,我在 wwwroot 中创建了一个文件夹,并将其作为应用程序。使用 .net 4.0 添加应用程序池。启用 Windows 身份验证并禁用匿名身份验证。在应用程序池和 webapp 中设置服务帐户。 从VS我使用默认设置(不是预编译)部署到IIS(使用文件系统) 站点在 IIS 上运行良好。 但… 如果单击预编译设置进行部署。网站因 403 错误而失败。尝试了各种组合并且永远不会让预编译的工作。非预编译时始终有效。

ASP.NET 4 已在 IIS 中注册。 尝试过的模块 runAllManagedModulesForAllRequests="true" 没有成功。

我没有想法,正在寻求帮助

Server Error in Application "xxx/MVCHELLOWORLD"

Internet Information Services 7.5



Error Summary 
HTTP Error 403.14 - Forbidden

The Web server is configured to not list the contents of this directory.


Detailed Error Information 


Module
DirectoryListingModule 

Notification
ExecuteRequestHandler 

Handler
StaticFile 

Error Code
0x00000000 



Requested URL
http://xxx/MvcHelloWorld/ 

Physical Path
C:\inetpub\wwwroot\MvcHelloWorld\ 

Logon Method
Negotiate 



Most likely causes: •A default document is not configured for the requested URL, and directory browsing is not enabled on the server.


Things you can try: •If you do not want to enable directory browsing, ensure that a default document is configured and that the file exists.
• Enable directory browsing using IIS Manager. 1.Open IIS Manager.
2.In the Features view, double-click Directory Browsing.
3.On the Directory Browsing page, in the Actions pane, click Enable.

•Verify that the configuration/system.webServer/directoryBrowse@enabled attribute is set to true in the site or application configuration file.


Links and More InformationThis error occurs when a document is not specified in the URL, no default document is specified for the Web site or application, and directory listing is not enabled for the Web site or application. This setting may be disabled on purpose to secure the contents of the server. 
View more information »

【问题讨论】:

403 错误太笼统了。查找实际错误。 我同意,但这就是错误。 ***.com/questions/5385714/… 尝试使用搜索。 ***.com/questions/1741439/… 我已经做了很多搜索,但我没有找到任何“预编译”是一个因素的地方。大多数搜索像 1741439,即使没有预编译,他们也会得到 403。如果这是重复的,我肯定想知道它的重复是什么。 【参考方案1】:

我刚遇到同样的问题,最近几天一直在尝试解决它。​​

我有一台运行 IIS 8 Express 的 Windows 8 电脑。

我复制了一个从另一台 PC 编译和发布的 MVC 站点,运行它,并得到与上述相同的 403.14 禁止。然后我尝试发布未编译的站点并运行它,并且站点加载得很好。

然后我决定在 Windows 8 电脑上加载 Visual Web Express,并创建了一个虚拟 MVC 站点,并在编译和未编译的情况下运行它,它工作得很好。这向我表明 IIS 8 Express 已配置并正常工作,并且该站点的编译方式肯定存在一些问题。

我在发布期间尝试了不同的预编译方法,包括不合并、全部合并和合并每个文件夹,但这些方法没有任何区别。

最后,我通过将项目中引用的每个程序集的 Copy Local 属性更改为 true 来解决这个问题。甚至所有应该从 GAC 引用的默认值。

不确定我是否需要将每个程序集复制到 bin 文件夹,但考虑到我的项目中引用的大量程序集,这似乎比一个接一个地尝试更容易。

编辑:进行了一些更改并重新发布了该网站,现在我又回到了 403.14 禁止 :(

我真的很想知道为什么它不起作用。

【讨论】:

以上是关于如何为 Intranet 预编译 MVC?的主要内容,如果未能解决你的问题,请参考以下文章

如何为 Android 不同平台打包原生预建库

如何为不断增长的 Eigen::MatrixXd 预分配内存

MVC 5 - 预编译视图仅适用于命令提示符

[转载].NET MVC4 Razor 视图预编译

ASP.NET MVC5 视图预编译

在 asp .net mvc 5 中预编译剃须刀视图