Copy Code code as follows:
Because I did not use the master page to do, so I can not be unified in the master page to judge permissions, and I was limited to their own level, and did not inherit from the page of this class method to unify the processing of some of the page load to deal with things. Now according to "Li Tianping (Dynamic Soft)" Some code records, also hope that we should learn to use inheritance Ah!
Look at a simple pagebase that inherits from page:
Copy Code code 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>
The I-write by Li Tianping
Up by Ahuinan 2009-4-18
</summary>
public class PageBase:System.Web.UI.Page
{
Public Pagebase ()
{
//
TODO: Add 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);
}
Error handling
protected void Pagebase_error (object sender, System.EventArgs e)
{
String errmsg = String. Empty;
Exception currenterror = HttpContext.Current.Server.GetLastError ();
ErrMsg + = ""This information has been logged by the system, please try again later or contact your administrator." <br/> "+
"Error Address:" + Request.Url.ToString () + "<br/>" +
"Error message:" + currentError.Message.ToString () + ""<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 bar sosuo8.com Landing test");
}
Else
{
HttpContext.Current.Response.Write ("You are not Ahanan, do not log in");
}
}
}
}
When in use:
Copy Code code as follows:
Public partial class _default:P agebase
{
protected void Page_ Load (object sender, EventArgs e)
{
int ID = Int. Parse (request.querystring["ID"]);
Response.Write ("ID:" +id.) ToString ());
}
}