简体   繁体   English

在dll中集成ASP.NET MVC Razor Views

[英]Integrate ASP.NET MVC Razor Views inside dll

I have ASP.NET MVC 5.2.6 project, In short, when I want to publish the website, I do not want to publish the Views as loose *.cshtml files in the Views folder, I want to integrate the Views inside a dll. 我有ASP.NET MVC 5.2.6项目,总之,当我要发布的网站,我没有要发布的视图作为松散*.cshtml的文件Views文件夹,我要整合一个DLL中查看。

I found this question , it is talking about compiling the ASP.NET MVC Razor Views, I applied it and it worked for me, and I was able to compile the ASP.NET MVC Razor Views, but I could NOT get rid of them, when I deleted the *.cshtml files, the website is no longer working, that is mean that the views do not go inside a dll. 我发现了这个问题 ,它是关于编译ASP.NET MVC Razor视图的,我应用了它并且对我有用,并且我能够编译ASP.NET MVC Razor视图,但是我无法摆脱它们,当我删除* .cshtml文件时,该网站不再工作,这意味着视图不在dll中。

Here is the Error when I delete the Views folder 这是删除Views文件夹时的错误

在此处输入图片说明

which is obviously, say that he could not find the view. 这显然是说他找不到视图。 Should I write some code to manipulate the Razor search Engine to enforce it to look inside the dll? 我是否应该编写一些代码来操纵Razor搜索引擎以强制其在dll中查找?

The link of the answer you aadded to your post is sufficient during developement process so it helps you to detects all compile errors and not on at execution where views are compiled on the fly. 在开发过程中,您添加到答案上的答案的链接就足够了,因此它可以帮助您检测所有编译错误,而不是在视图被即时编译的执行时发现。

It's is rare to compile the views into DLL during developement. 在开发过程中很少将视图编译为DLL。 You need to compile them per view, per folder, per page and control, or into one single DLL only during publishing your application. 仅在发布应用程序时,才需要针对每个视图,每个文件夹,页面和控件将它们编译到一个DLL中。

So into your publishing profile settings which look like this: 因此,您的发布配置文件设置如下所示:

在此处输入图片说明

Click on Configure link and after that you will have this dialog window: 单击配置链接,然后您将看到以下对话框窗口:

在此处输入图片说明

In the winfow above you can choose which compiling option you want. 在上方的winfow中,您可以选择所需的编译选项。

Again you don't need to compile your views into a DLL during developement process. 同样,在开发过程中无需将视图编译为DLL。 During that process just modify the csproj and it is enough. 在此过程中,只需修改csproj就足够了。

This is probably what you are looking for: https://github.com/RazorGenerator/RazorGenerator 这可能是您要寻找的: https : //github.com/RazorGenerator/RazorGenerator

This will generate your view files as a single dll for you. 这会将您的视图文件生成为单个dll。

Although I may not totally understand or agree with the reasoning's for this approach to your solution as this doesn't necessarily provide a better security mechanic as dll's can be decompiled and the source taken out. 尽管我可能不完全理解或不同意这种方法对您的解决方案的推理,因为这不一定能提供更好的安全机制,因为可以对dll进行反编译并删除源代码。 If you have good security within the server and follow best practices having the raw html files may be easier to manage. 如果您在服务器内具有良好的安全性并遵循best practices ,则原始html文件可能更易于管理。

After some thinking the only way I can think of even trying what you ask is generating the cshtml files on the fly in code. 经过一番思考后,我什至可以尝试尝试的唯一方法就是在代码中动态生成cshtml文件。 But I've never even thought of trying that before. 但是我从来没有想过尝试过。

I think the real answers are getting the security policy changed as it is no fit for purpose. 我认为真正的答案是改变安全策略,因为它不适合目标。 Or using something other than ASP.NET MVC. 或使用ASP.NET MVC以外的工具。

After all ASP.NET MVC in the end is simply sending files to a client that has requested them. 毕竟,ASP.NET MVC毕竟只是将文件发送到已请求文件的客户端。

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

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