Add your own features and code to your. Net Web products?

Source: Internet
Author: User
Tags terminates

Background:

Recently there is a project, a friend to find a more mature online CMS system (dynamic Easy), let me add some features to him, this product features quite a lot, but no source code. According to the previous practice, is to directly decompile his DLL, generate source code, and then on the basis of the source code to modify and improve their own functionality. But the study of this product, the bin under the DLL very much, there are major, and auxiliary. If each DLL is decompile, it is simply unrealistic.

?

Using a hair-compiling tool ? Ilspy Open the inside several main DLL, found also add shell confusion, with De4dot anti-confuse out. The code inside is still very clear, but if every dll is doing it, it will be exhausting.

?

Workaround:

aWebthe project has a majorDLL, the others are auxiliaryDLL, mainlyDLLdependent on the secondaryDLL. I can build myself aDLL, reference auxiliaryDLL. And then let his LordDLLCall MyDLL. (Here is the premise that hisDLLThere is no strong name protection, if there is, can not be used directly, need to remove their strong name protection to use this way)

?

Start Step:

The first step is to create a blank module ( DLL module, or WEB module, recommended is WEB , because the page may be added), it needs to write some of our features and methods.

The second step, open the new project directory, put someone else's system program ( WEB root directory) copy to the project below (note that the Copy folder arrives in a project folder, all covered, not directly copied VS within the project, there is a difference between the two.

Third step, then go back to the project, click "Refresh", "Show All Files".

is not all the documents come in, it is important to remember that no other people's files included in the project, must be ruled out.

Fourth Step, reference DLL all of the following auxiliary DLL that this you need to understand that his Lord DLL You can't quote, you must find the right one.

your project and the others ' DLL used by . NET Framework must be consistent, others are 2.0 you also have to be 2.0 , the principle you should understand.

?

Fifth step, you can start to add our programs and functions.

we assume that one of his pages has a problem with the functionality, how we can modify this feature, and if some of his pages are not extracted, how do we go directly to extract the data. Of course, we can directlyaspxthe code that adds the database operation to the page is read directly, but in this case it may be completely out of sync with some of his programs, for example, we should shareSession,Cookies, there are a number of global variables and methods that can be reused without a newaspxpage to write these methods. The fourth step is to quote someone else'sDLL, but also in order to achieve the maximum use of his resources, he has, we try not to write, he did not, we can go to write, but also to maintain a whole with him.

?

A simple example, Want to give a content page to add the function of mobile phone sharing (mobile sharing can correctly display the share title picture and description). The corresponding Address page is /item/ number .aspx /item.aspx?id= number.

We open item.aspx look inside the content.

?

You find that this page is nothing, you think you can write code in this, you find that you write any code will not be displayed.

Because all the information on this page is the background template parsing, and then output, if you write the static content on this page, you see if he output?

When you execute this page through your browser, you find that it does not have your content output. What if we add page_onload ? Will it be executed and you will find that it will certainly not be executed, and will not output anything, or pass ? Ilspy Go and see other people's source code.

turns out, he's onload one of the previous methods has been response.end ( default = true) , so that the thread terminates, it will not be executed to your method. To see what his events were.

as you can see, he executes the top of the page event PreInit. and then at the end of the day directly End terminates the thread.

?

And to execute our code, we have to find an event before him, so we can execute our method.

through the ASP. NET page life cycle: from Onpreinit to end Render , we can see. There's a way to determinepostbackmode before he does.

By testing, our "test" text is output to his content.

?

here's how to invoke our project DLL Method

?

One approach is to go directly through

embedding method, this method is dynamically compiled and executed. This approach may be a lot of people, and I need to say another way to call our DLLs through reflection .

?

in the second approach, we Lib/fun.cs write the following code in the

There are three questions to note here, and the first one is Fun.cs can not be included in project engineering, the second problem is the first parameter of the function, the function of the first parameter is to cache the dynamically created object. A third question. Why use the Flow method when loading assemblies dynamically. Tell everyone, there is a reason.

?

first one Fun.cs not included in the project is understandable. Because he's part of someone else's product, not part of my product.

a second obj parameter issues, for caching dynamically created cases, why not create one case at a time?

The third way to load an assembly is file.load. However, this loading is not easy to release, compile time will often appear dll is being used, the second, if loaded every time, will be used as a DLL reuse. If serialization and deserialization are present, conversion problems may occur. This is also the answer to the second question.

?

So where do we put this cached object, as long as it's Static you can put it in Global.ascx can also be placed in other aspx the page.

?

Execute method is to call us through reflection DLL in Weixin Inside of this method, so we can write arbitrary public methods within this, but conform to the rules we call.

?

Continue later.

?

?

?

?

?

?

Add your own features and code to your. Net Web products?

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.