CopyCode The Code is as follows: isadmin ();
Because the master page was not used at the time, the master page cannot be used to determine the permissions in a unified manner. At that time, I was limited to my own level, the method of inheriting from the page class is not used to process all the things that need to be handled during page loading. According to some code records of "Li Tianping (dynamic soft)", I hope you will learn how to use inheritance!
Let's look at the next simple pagebase inherited from the page:Copy codeThe Code is as follows: using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. htmlcontrols;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
/// <Summary>
/// First write by Li Tianping
/// Up by ahuinan 2009-4-18
/// </Summary>
Public class pagebase: system. Web. UI. Page
{
Public pagebase ()
{
//
// Todo: add the constructor logic here
//
}
Protected override void oninit (eventargs E)
{
Base. oninit (E );
This. Load + = new system. eventhandler (pagebase_load );
This. Error + = new system. eventhandler (pagebase_error );
}
// Handle errors
Protected void pagebase_error (Object sender, system. eventargs E)
{
String errmsg = string. empty;
Exception currenterror = httpcontext. Current. server. getlasterror ();
Errmsg + = ""This information has been recorded by the system. Please try again later or contact the administrator. <Br/> "+
"Error address:" + request. url. tostring () + "<br/>" +
"Error message:" + currenterror. Message. tostring () + "<HR/>" +
"<B> stack trace: </B> <br/>" + currenterror. tostring ();
Httpcontext. Current. response. Write (errmsg );
Server. clearerror ();
}
Private void pagebase_load (Object sender, eventargs E)
{
If (! Page. ispostback)
{
If (httpcontext. Current. session ["username"]! = NULL)
{
Httpcontext. Current. response. Write ("Search for sosuo8.com logon test ");
}
Else
{
Httpcontext. Current. response. Write ("You are not a kinnan, do not log on ");
}
}
}
}
When using:Copy codeThe Code is as follows: public partial class _ default: pagebase
{
Protected void page_load (Object sender, eventargs E)
{
Int id = int. parse (request. querystring ["ID"]);
Response. Write ("ID:" + id. tostring ());
}
}