ASPX does not use code-behind to work with common code workarounds

Source: Internet
Author: User
Tags processing instruction reflection

Recently made a brinkster of space found uploaded a compiled site after said to find the path set hint for "Xxx.dll" did not compile for n long or did not find the reason. Later on this machine I put a Web site into the wwwroot without giving it a virtual directory directly in IIS Browse discovery and space errors exactly the same: To know that the uploaded site did not create a virtual directory, but the site does not allow me to create a virtual directory. There's nothing left to think about. Long time found that this space does not support code-behind only using single-page aspx what to do my many of the code is encapsulated into a class placed in the App_Code folder in a single-page aspx that is simply inaccessible. Urgent a site to I re-make a copy of the page. I'm dizzy ... There is no other way to think about it. Slowly began to do a single page of the day before the code is the same as long as the copy on the line can be in the background CS How to do I can not make some public methods in each page may be called in this page written in another page in the same to write ... So much work and my database operations are written in the class. No words anymore. Silent ... Hey, the programmer is commiseration. The code that knocked over is also knocked and the methods in the class are put into ASPX and the ASPX appears cluttered and the file is large ... Wrestling still no result. Some people say to inherit the System.Web.UI.Page class aspx single page how to inherit AH. So I went on thinking, thinking. See Import in the page this processing instruction so I began to encapsulate the class as a DLL. To the page to reference the DLL can be private dll No bin directory is always referenced in aspx. Suddenly I thought of the reflection I had seen before. Yes, with reflection on it, so. I'll look for the reflective information. To invoke a method in a DLL dynamically: I have chained all the database query methods to the DLL. The method is then invoked by reflection. Haha, the problem is solved. In the process of using reflection also encountered some trouble. But the general direction has. It was solved in one by one.

Reflection refers to namespaces system.reflection .......

Assembly assembly=assembly.loadfrom ("Xxx.dll");

Type[] tt=assembly. GetTypes ();

foreach (Type t in TT)

{

if (t.fullname== "Database.connection")

{

Object O=activator.createinstance (t);

MethodInfo M=t.getmethod ("MethodName");

object[] parm=new object[]{};//parameters

Object Result=m.invoke (O,parm);

Return result;//implements the method in the dynamic call DLL

}

}

I put the DLL file in a separate folder ... This reduces the foreground code can also be implemented in the public also to some extent to prevent the logic confusion of the foreground code.

Rest and Rest .... The problem is solved. haha haha haha

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.