Today, when I was looking at the development of the Asp.net Server Control, I saw that all of the above is based on countrol inheritance, and then rewrite the method to achieve some basic effects.
As a result, I will inherit the page class and rewrite its method to achieve the most basic problems such as determining whether a user is logged on or not during page loading.
The following is the simplest way to determine whether a user is logged on.
CodeAs follows:
Using system; <br/> using system. collections. generic; <br/> using system. LINQ; <br/> using system. web; <br/> using system. web. ui; </P> <p> namespace webapplication1 <br/>{< br/> public class roots: page <br/>{< br/> protected override void oninit (eventargs e) <br/>{< br/> If (session ["username"] = NULL) <br/> {<br/> response. redirect ("login. aspx "); </P> <p >}< br/> base. oninit (E); <br/>}</P> <p >}< br/>
I wrote a roots class, inherited the page, and then rewritten the oninit method (for details about the page lifecycle, refer to here)
Then you can inherit the roots class on the page you want to verify.
For example, Main. aspx
Public partial class main: roots <br/>{< br/> protected void page_load (Object sender, eventargs E) <br/>{</P> <p >}< br/>
When your tag is empty, the logic in your oninit statement is executed.
Of course, many general functions can be implemented through rewriting, such as the master style and different logon permissions of different users.
I am here to discuss the issue. I hope to learn from you.