[英]Is it possible to use virtual path provider with DotNetNuke?
We have a DNN module that uses Angular as its client side framework. 我们有一个DNN模块,它使用Angular作为其客户端框架。 I'd like to be able to embed all the resources such as html , js ,css ,images and fonts to my module.(actually our module have more than one dll and every one of them has its own resources so that I don't want to copy all of these resource into main module folder every time I want to make a package)
我希望能够将所有资源(如html,js,css,图像和字体)嵌入到我的模块中。(实际上我们的模块有多个dll,每个都有自己的资源,所以我不会我希望每次想要制作包时将所有这些资源复制到主模块文件夹中)
So far I have tried WebResource.axd which was successful to some extent ( Here 's what I have done)but then I realized that It is somehow impossible to embed html,images and other stuffs rather than js and css (or it isn't?) 到目前为止,我已经尝试了WebResource.axd,这在某种程度上是成功的( 这就是我所做的)但后来我意识到,以某种方式嵌入html,图像和其他东西而不是js和css(或者它不是' ΔT)
Then I decided to try using VirtualPathProvider and I used this open source project that implements an EmbeddedResourcesVirtualProvider. 然后我决定尝试使用VirtualPathProvider,我使用了这个实现EmbeddedResourcesVirtualProvider的开源项目 。
I have registered this provider using IRouteMapper interface of DNN. 我已经使用DNN的IRouteMapper接口注册了此提供程序。 Now that I start testing my project I am getting 404 for all of my resources.
现在我开始测试我的项目,我的所有资源都获得了404。 I tried to debug the project and put some break points over FileExists ,DirectoryExists and GetFile methods of VirtualProvider but the only virtual path that is being asked from VirtaulProvider is "~/Default.aspx" and nothing else
我尝试调试项目并在VirtualProvider的FileExists,DirectoryExists和GetFile方法上设置了一些断点,但是从VirtaulProvider询问的唯一虚拟路径是“〜/ Default.aspx”而没有别的
I would like to ask if it is possible to use VirtualParhProvider with DNN ? 我想问一下是否可以将VirtualParhProvider与DNN一起使用?
We are using DNN 8. 我们正在使用DNN 8。
I think you are over complicating things a bit. 我认为你有点过于复杂化了。 If you need a virtual provider for your module to work you are doing it wrong (in my opinion).
如果您的模块需要虚拟提供程序,那么您做错了(在我看来)。 A module should be a self-contained package that could be deployed on any DNN installation without having to do anything but install the module.
模块应该是一个独立的软件包,可以部署在任何DNN安装上,而无需执行任何操作,只需安装模块即可。
Normally when you buy or download a free module , it comes in a single zip file with all the necessary files contained in that zip. 通常,当您购买或下载免费模块时 ,它会包含一个zip文件,其中包含该zip文件中包含的所有必需文件。 That could be any type of file (.dll, .js, css, .ascx, .aspx etc) is does not matter as long as it's defined in the
.dnn
installation file. 这可以是任何类型的文件(.dll,.js,css,.ascx,.aspx等),只要它在
.dnn
安装文件中定义就.dnn
。
You can then link to the files in the ascx of your module. 然后,您可以链接到模块的ascx中的文件。
<script type="text/javascript" src="/DesktopModules/YourModulePath/js/file.js"></script>
or
<img src="/DesktopModules/YourModulePath/images/image.jpg">
With WebResource you can embed anything - images, html, fonts etc., so I would suggest continuing with the approach you've already taken. 使用WebResource,您可以嵌入任何内容 - 图像,html,字体等,因此我建议您继续使用已经采用的方法。
I downloaded and installed your module in DDN 8 for testing. 我在DDN 8中下载并安装了您的模块以进行测试。 So the following assumes that setup.
所以以下假定设置。
In the library MyFramework
: 在
MyFramework
库中:
image.png
to a new folder \\content\\images\\
image.png
的文件添加到新文件夹\\content\\images\\
Build Action
to Embedded Resource
for this image Build Action
到Embedded Resource
[assembly: System.Web.UI.WebResource("MyFramework.content.images.image.png", "image/png")]
to AssemblyInfo.cs
[assembly: System.Web.UI.WebResource("MyFramework.content.images.image.png", "image/png")]
到AssemblyInfo.cs
protected string myImageUrl { get; private set; }
protected string myImageUrl { get; private set; }
protected string myImageUrl { get; private set; }
protected string myImageUrl { get; private set; }
so we can access the URL in the inheriting class protected string myImageUrl { get; private set; }
这样我们就可以在继承类访问URL myImageUrl = Page.ClientScript.GetWebResourceUrl(typeof(MyModuleBase), "MyFramework.content.images.image.png");
myImageUrl = Page.ClientScript.GetWebResourceUrl(typeof(MyModuleBase), "MyFramework.content.images.image.png");
to your OnInit()
method OnInit()
方法 In the consuming project MyModule
: 在消费项目
MyModule
:
<img src="<%=myImageUrl%>"/>
to View.ascx
<img src="<%=myImageUrl%>"/>
到View.ascx
In the library MyFramework
: 在
MyFramework
库中:
myhtml.html
to a new folder \\content\\html\\
(in my file I have: <div style="font-weight: bold;font-size: x-large">Some <span style="color: orange">HTML</span></div>
) myhtml.html
的文件添加到新文件夹\\content\\html\\
(在我的文件中我有: <div style="font-weight: bold;font-size: x-large">Some <span style="color: orange">HTML</span></div>
) Build Action
to Embedded Resource
for the html Build Action
到Embedded Resource
[assembly: System.Web.UI.WebResource("MyFramework.content.html.myhtml.html", "text/html")]
to AssemblyInfo.cs
[assembly: System.Web.UI.WebResource("MyFramework.content.html.myhtml.html", "text/html")]
到AssemblyInfo.cs
protected string MyHtmlUrl { get; private set; }
protected string MyHtmlUrl { get; private set; }
protected string MyHtmlUrl { get; private set; }
protected string MyHtmlUrl { get; private set; }
so we can access the HTML in the inheriting class protected string MyHtmlUrl { get; private set; }
这样我们就可以在继承类访问HTML var assembly = Assembly.GetExecutingAssembly(); var resourceName = "MyFramework.content.html.myhtml.html"; using (Stream stream = assembly.GetManifestResourceStream(resourceName)) { using (StreamReader reader = new StreamReader(stream)) { MyHtmlUrl = reader.ReadToEnd(); } }
In the consuming project MyModule
: 在消费项目
MyModule
:
<%=MyHtmlUrl%>
to View.ascx
<%=MyHtmlUrl%>
添加到View.ascx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.