ASP. NET encapsulates JS files into DLL

Source: Internet
Author: User

The manager told me yesterday. Is there any way to make users unable to see JS and do not want users to modify JS files. In case of program confusion. I have never done this before, and I have never thought about this problem. I found it online today. Finally, there is a result.

Step 1: Create a project)

Find the AssemblyInfo. CS file and add the resource file to the file. Add the following code to the end of the document:

[Assembly: WebResource ("ClassLibrary1.JScript1. js", "application/x-javascript")]

 

ClassLibrary1 is the project namespace. If there is no namespace, you don't need to write it. You just need to write the file name.

Create a class file here because the demo I wrote is not too standard, the Class1

 

Code

Public class Class1: WebControl
{
Protected override void OnPreRender (EventArgs e)
{
If (this. Page! = Null)
{
If (manager_JSname = "JScript1 ")
{
ClientScriptManager manager1 = this. Page. ClientScript;
Manager1.RegisterClientScriptResource (typeof (Class1), "ClassLibrary1.JScript1. js ");
}
Else if (manager_JSname = "JScript2 ")
{
ClientScriptManager manager2 = this. Page. ClientScript;
Manager2.RegisterClientScriptResource (typeof (Class1), "ClassLibrary1.JScript2. js ");
}

}
Base. OnPreRender (e );

}
Private string manager_JSname;

Public string Manager_JSname
{
Get {return manager_type ;}
Set {manager_type = value ;}
}
}

 

 

Then write on the page file

Write on the page header

<% @ Register Assembly = "ClassLibrary1" Namespace = "ClassLibrary1" TagPrefix = "PC3" %>

Content Center

<PC3: Class1 runat = "server" ID = "class1" manager_JSname = "JScript1"> </PC3: Class1>

 

 

 

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.