<<ABP documents >> Embedded Resource files

Source: Internet
Author: User
Tags script tag

Document Directory

The content of this section:

    • Brief introduction
    • Create an embedded file
    • Exposing embedded files
    • Using an embedded file

Brief introduction

In a Web application, the client contains files such as Javascript,css,xml, which are added to a Web project, published as separate files, and sometimes we need to package some of these files into an assembly (a class library project, a DLL file), And as an embedded resource file deployed in this assembly, the ABP provides an infrastructure to easily handle this matter.

Create an embedded file

We first create a resource file and mark it as an embedded resource, and any assembly can contain an embedded resource file, assuming we have an assembly called "Abp.Zero.Web.UI.Metronic.dll" that contains javascript,css and picture files:

We want to use these files in a Web application, first of all, we should modify the build action of the file we want to expose to embedded Resource (the embedded Resource). I select the Metronic.js file, go to the Properties window (shortcut key is F4) and modify it.

You should modify the build operation of all the files you want to use into an embedded resource in a Web application.

Exposing embedded files

The ABP can easily expose embedded resource files with just one line of code:

Webresourcehelper.exposeembeddedresources ("abpzero/metronic""  Abp.Zero.Web.UI.Metronic");

This code is usually placed in the initial method of the module, let's explain its parameters:

    • The first parameter defines the root directory of the file, which matches the root namespace.
    • The second parameter defines the file that the assembly contains, and in this case I pass the assembly that contains the code, but you can pass any assembly that contains the embedded resource.
    • The last parameter defines the root namespace of these files in this assembly, which is the "default namespace" + "directory in this Assembly", the default namespace is usually the same as the assembly name, but can be modified in the properties of the assembly, where the default namespace is ABP (I modified it), So the Metronic directory namespace is "Abp.Zero.Web.UI.Metronic".

Using an embedded file

You can use the embedded file directly:

<script type="text/javascript" src="~/abpzero/metronic/ Assets/global/scripts/metronic.js"></script>

ABP can understand that this is an embedded file and get all the previously exposed files of the DLL, although it can simply work, you can use the ABP htmlhelper extension method in a razor view Includescript:

@Html. Includescript ("~/abpzero/metronic/assets/global/scripts/metronic.js")

This will generate the script tag as shown below:

<script src="/abpzero/metronic/assets/global/scripts/metronic.js?  v=635438748506909100 "type="text/javascript"></script>

The only difference is the v=635438748506909100 parameter, which blocks the default cache of the browser's script, which changes only when your DLL is regenerated (essentially, the last modified time of the file), and if a change occurs, the browser no longer caches the old one. It is recommended to use the Includescript method, and it can also be used for non-embedded physical files, as well as a Includestyle method for CSS files.

<<ABP documents >> Embedded Resource files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.