如何将 ASP.NET 母版页存储在公共库中?
我们希望有几个使用相同母版页的内部 Web 应用程序。 有没有办法将母版页存储在所有项目引用的公共库中?
We would like to have several internal web applications which use the same master page. Is there a way to store a master page in a common library referenced by all projects?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以做到这一点,但这很困难并且有很多缺点。
此过程也类似于打包用户控件。 基本上,您有一个包含母版页的 Web 应用程序项目。 您可以使用 aspnet_compiler 将其预编译为一组 dll。
然后您可以使用 ilmerge.exe 将它们全部放入一个 dll 中,然后从其他项目中引用该 dll。
您仍然需要标记才能使页面在设计器中正确呈现,因此您可能还需要研究 VirtualPathProviders。
这是一个笨拙的解决方案,并且有很多缺点。
You can do this, but it is difficult and has quite a few drawbacks.
This process is similar to packaging up user controls as well. Basically you have a web application project that contains your master page. You can precompile this into a set of dlls using aspnet_compiler.
then you can use ilmerge.exe to put them all into a single dll that you then reference from your other projects.
You still need to have the markup in order for your pages to render properly in the designer, so you'll probably have to investigate VirtualPathProviders as well.
It's a kludgy solution and it has many drawbacks.
我听说这个有效,但我没有测试过。
创建一个单独的项目来容纳您的母版页,因为所有母版页都类似于用户控件并内置到它们自己的单独程序集中。 运行构建并尝试引用母版页的程序集。
再说一遍,未经测试,只是我之前读过的内容。
祝你好运!
I've heard this works, I haven't tested it.
Create a separate project to house your master pages, since all master pages are like user controls and built into their own separate assembly. Run the build and try referencing the assembly of the master page.
Again, not tested, just something I've read before.
G'luck with it!
鉴于这些模块是同一 Web 应用程序的一部分,您应该查看 这种方法:
基本上,您有一个根 Web,它被设置为(唯一的)IIS Web应用。
您可以通过创建 ASP.NET Web 应用程序项目来插入新的 Web 模块,并将其物理地放置在根 Web 下。
将构建目录设置为 root web 的 bin,例如。 “..\垃圾桶”。 不要创建 IIS 应用程序/虚拟目录。
因此,每个 Web 模块都会编译成自己的 DLL,这本身就是一件好事。
编译时,它与根网络“合并”。
这是共享母版页和用户控件的好方法,并且在不同的项目/程序集中具有网站的不同部分。
母版页和用户控件甚至可以在设计模式下工作。
Given that these modules are part of the same web application, you should look at this approach:
Basically, you have one root web, which is set up as the(only) IIS web application.
You may plug in new web modules by creating ASP.NET Web Application projects and place under the root web, physically.
Set the build directory to root web's bin, eg. "..\bin". Don't create a IIS application/virtual directory.
Thereby, each web module compiles into its own DLL, which is itself a good thing.
When compiling, it is "merged" with the root web.
It is a great way for sharing master pages and user controls, and have different parts of the web site in different projects/assemblies.
Master pages and user controls will even work in design mode.
希望这可以帮助
在应用程序中共享母版页
享受吧。 。:)
Hope this helps
Sharing master page across the application
Enjoy.. :)