I tried to precompile my ASP.NET MVC application and deploy it to an IIS6 box (with wildcard mapping), however I am getting an error with rendering partial views (user controls). Its working fine on my dev machine before precompiling.
我试图预编译我的ASP.NET MVC应用程序并将其部署到IIS6框(带通配符映射),但是我在渲染部分视图(用户控件)时遇到错误。在预编译之前,它在我的开发机器上正常工作。
The error is:
错误是:
Server Error in '/' Application.
The partial view 'ListGrid' could not
be found. The following locations were
searched:
~/Views/Initiative/ListGrid.aspx
~/Views/Initiative/ListGrid.ascx
~/Views/Shared/ListGrid.aspx
~/Views/Shared/ListGrid.ascx'/'应用程序中的服务器错误。找不到部分视图'ListGrid'。搜索了以下位置:〜/ Views / Initiative / ListGrid.aspx~ / Views / Initiative / ListGrid.ascx~ / Views / Shared / ListGrid.aspx~ / Views / Shared / ListGrid.ascx
I checked Views\Shared for the file and it was not there, which I thought was normal because its precompiled. But just for giggles I put a blank file in that folder names ListGrid.ascx, but then I got this error:
我检查了Views \ Shared的文件,它不存在,我认为这是正常的,因为它预编译。但只是为了咯咯笑,我在该文件夹中放了一个空白文件名为ListGrid.ascx,但后来我收到了这个错误:
Server Error in '/' Application.
The file '/Views/Shared/ListGrid.ascx'
has not been pre-compiled, and cannot
be requested.'/'应用程序中的服务器错误。文件'/Views/Shared/ListGrid.ascx'尚未预编译,无法请求。
I googled and searched SO but could not find any similar problems, but had no luck.
我用Google搜索并搜索了但是找不到任何类似的问题,但没有运气。
2 个解决方案
#1
3
Although you can precompile an MVC site the ascx and aspx view files are not in the compiled dll only the .cs files are. You will still need to deploy the .aspx and .ascx view files.
虽然您可以预编译MVC站点,但ascx和aspx视图文件不在编译的dll中,只有.cs文件。您仍然需要部署.aspx和.ascx视图文件。
Hope this helps
希望这可以帮助
#2
16
You can precompile an MVC app by placing this in the post-build actions in project properties:
您可以通过将其置于项目属性中的后构建操作中来预编译MVC应用程序:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler -p "$(ProjectDir)." -v /$(ProjectName)
This takes a little longer than without it, however you get the added ability to detect some errors that would occur at runtime prior to deployment.
这比没有它需要更长的时间,但是您可以更好地检测在部署之前在运行时发生的一些错误。
Compilation will fail if you have invalid code in your views or are missing views by using this method.
如果视图中的代码无效或者使用此方法缺少视图,则编译将失败。
#1
3
Although you can precompile an MVC site the ascx and aspx view files are not in the compiled dll only the .cs files are. You will still need to deploy the .aspx and .ascx view files.
虽然您可以预编译MVC站点,但ascx和aspx视图文件不在编译的dll中,只有.cs文件。您仍然需要部署.aspx和.ascx视图文件。
Hope this helps
希望这可以帮助
#2
16
You can precompile an MVC app by placing this in the post-build actions in project properties:
您可以通过将其置于项目属性中的后构建操作中来预编译MVC应用程序:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler -p "$(ProjectDir)." -v /$(ProjectName)
This takes a little longer than without it, however you get the added ability to detect some errors that would occur at runtime prior to deployment.
这比没有它需要更长的时间,但是您可以更好地检测在部署之前在运行时发生的一些错误。
Compilation will fail if you have invalid code in your views or are missing views by using this method.
如果视图中的代码无效或者使用此方法缺少视图,则编译将失败。