Compile the aspx file in ASP. NET

Source: Internet
Author: User

Compile a single aspx file into a DLL

Microsoft does not allow developers to directly compile the aspx file into a DLL from the "Implication" publicly described by Microsoft in the previous section. However, ASP. NET Advanced Interface Technology Server HTML controls, WEB controls, etc.) are all presented through the aspx file, if you give up the advanced features of aspx for DLL running efficiency, it is obvious that you have never had to give it a try.

Now let's take a look:

The csc compiler is only a c # Language compiler. It can only compile files that comply with the C # language specification, while the aspx file format obviously does not comply with the c # language specification, therefore, the csc compiler cannot compile the aspx source file.

Therefore, to compile the aspx file into a dll file, you must first convert the aspx file into a cs source file that the csc compiler can recognize. So what tools are used for conversion? Although I believe that this tool must be hidden. Net Framework, but after reading a large number of ASP. NET and. Net public documents and reference manuals, the relevant information is still not found.

Oh, there is no path to death, and I am still able to discover this secret by chance.

Let's take a look at the source file ex2.aspx:

 
 
  1. <% @ PageLanguage="C #"%> 
  2. <Script Runat="Server"> 
  3. Abcdefg // code trap
  4.  
  5. Void Page_LoadObject src, EventArgs args)
  6. {
  7. If! IsPostBack)NoteLabel. Text="Enter your name :";
  8. }
  9. Void OnNameSubmitObject src, EventArgs args)
  10. {
  11. StringName=F_Name. Value;
  12. NoteLabel. Text=Name= "")?
  13. }
  14. </Script> 
  15. <Html> 
  16. <Body> 
  17. <Form Runat="Server"> 
  18. <H1>DllTest-Ex2 Example 2)</H1> 
  19. <Hr> 
  20. <Asp: LabelRunat="Server" Id="NoteLabel" Style="Color: red;
    Font-weight: bold" /> 
  21. <Input Runat="Server" Id="F_Name" Size="8"> 
  22. <Button Runat="Server" Onserverclick="OnNameSubmit">OK</Button> 
  23. </Form> 
  24. </Body> 
  25. </Html> 

If you comment out or delete the "Code trap", ex2.aspx is a simple ASP. NET file. You can use IE to browse this page and find that it works properly.
Now let's open the "trap" to see what ASP. NET returns?

A "Compilation error" page is returned, and the report source file cannot be compiled. We are interested in a hyperlink at the bottom of the page named "show complete compilation sources". Click some links, you can see the complete content of the cs source file "Complete Compilation source" converted from ex2.aspx. Remove the preceding line number information from this part of "Complete Compilation source" and some other compilation switches, which are mainly # line compilation commands ), and close the cute "code trap" and use // to comment it out or delete it directly), and save it as ex2_aspx.cs.

I believe that after analyzing this file, you will have a better understanding of the ASP. NET operating principle, which is irrelevant to this article and will not be discussed in detail ).

In the command line status, use the following compilation command to compile ex2_aspx.cs into ex2.dll and store it in the bin directory.

Csc/t: library/out: bin \ ex2.dll ex2_aspx.cs

In the configuration file web. add aspx-> dll ing in config, that is, in system. add the following line to httpHandlers in the web Section: <add verb = "*" path = "dlltest2.aspx" type = "ASP. ex2_aspx, ex2 "/>

Now, when the browser accesses http: // localhost/dlltest/dlltest2.aspx, it is like accessing ex2.aspx. Of course, even if ex2.aspx does not exist or has been updated, it will not affect page access, unless the bin \ ex2.dll is regenerated.

  1. DataList and Repeater controls of ASP. NET
  2. Analysis of IIS ing in ASP. NET
  3. Overview ASP. NET status types
  4. Introduction to ASP. NET and Web servers
  5. EnableViewState attribute of ASP. NET

Related Article

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.