页面基类,写在Page_Load之前执行的类

一个在Page_Load之前执行的类,可以执行重写页面呈现,使所有页面拥有统一的特性;比如标题后缀和编写身份验证,IP限制访问等最高级别特性。

ContractedBlock.gif  
None.gifusing System;
None.gif
using System.Data;
None.gif
using System.Configuration;
None.gif
using System.Web;
None.gif
using System.Web.Security;
None.gif
using System.Web.UI;
None.gif
using System.Web.UI.WebControls;
None.gif
using System.Web.UI.WebControls.WebParts;
None.gif
using System.Web.UI.HtmlControls;
None.gif
ExpandedBlockStart.gif
/**//// <summary>
InBlock.gif
/// 页面基类 
ExpandedBlockEnd.gif
/// </summary>

None.gifpublic abstract class PageBase : System.Web.UI.Page
ExpandedBlockStart.gif
dot.gif{
ContractedSubBlock.gif    
重写方法,尽量只添加不修改。#region 重写方法,尽量只添加不修改。
InBlock.gif
ContractedSubBlock.gif    
重写页面第一次加载事件#region 重写页面第一次加载事件
ExpandedSubBlockStart.gif    
/**//// <summary>
InBlock.gif    
/// 重写页面第一次加载事件
InBlock.gif    
/// </summary>
ExpandedSubBlockEnd.gif    
/// <param name="e"></param>

InBlock.gif    protected override void OnPreInit(EventArgs e)
ExpandedSubBlockStart.gif    
dot.gif{
InBlock.gif        
this.ForwardOnPreInit();
InBlock.gif        
base.OnPreInit(e);
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif    
#endregion

InBlock.gif
ContractedSubBlock.gif    
重写页面呈现,使所有页面拥有统一的特性#region 重写页面呈现,使所有页面拥有统一的特性
ExpandedSubBlockStart.gif    
/**//// <summary>
InBlock.gif    
/// 重写页面呈现,使所有页面拥有统一的特性;比如标题后缀。
InBlock.gif    
/// </summary>
ExpandedSubBlockEnd.gif    
/// <param name="writer"></param>

InBlock.gif    protected override void Render(HtmlTextWriter writer)
ExpandedSubBlockStart.gif    
dot.gif{
InBlock.gif        
this.ForwardRender();
InBlock.gif        
base.Render(writer);
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif    
#endregion

InBlock.gif
ExpandedSubBlockEnd.gif    
#endregion

InBlock.gif
ContractedSubBlock.gif    
重写方法#region 重写方法
InBlock.gif
ContractedSubBlock.gif    
在页面第一次处理之前过程。#region 在页面第一次处理之前过程。
ExpandedSubBlockStart.gif    
/**//// <summary>
InBlock.gif    
/// 在页面第一次处理之前过程。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    private void ForwardOnPreInit()
ExpandedSubBlockStart.gif    
dot.gif{
InBlock.gif        
//这里编写身份验证,IP限制访问等最高级别特性。
ExpandedSubBlockEnd.gif
    }

ExpandedSubBlockEnd.gif    
#endregion

InBlock.gif
ContractedSubBlock.gif    
呈现HTML内容之前过程,对HTML内容进行整改。#region 呈现HTML内容之前过程,对HTML内容进行整改。
ExpandedSubBlockStart.gif    
/**//// <summary>
InBlock.gif    
/// 呈现HTML内容之前过程。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    private void ForwardRender()
ExpandedSubBlockStart.gif    
dot.gif{
ExpandedSubBlockStart.gif        
/**//// 呈现HTML内容之前过程。
InBlock.gif        this.Title += " - 网站标题后缀名字";
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif    
#endregion

InBlock.gif
ExpandedSubBlockEnd.gif    
#endregion

InBlock.gif
ContractedSubBlock.gif    
扩展属性#region 扩展属性
InBlock.gif
ContractedSubBlock.gif    
获取当前执行页面名和全部的查询字符串(如有)。#region 获取当前执行页面名和全部的查询字符串(如有)。
ExpandedSubBlockStart.gif    
/**//// <summary>
InBlock.gif    
/// 获取当前执行页面名和全部的查询字符串(如有)。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    protected string PageNameAll
ExpandedSubBlockStart.gif    
dot.gif{
InBlock.gif        
get
ExpandedSubBlockStart.gif        
dot.gif{
InBlock.gif            
if (ClientQueryString != "")
ExpandedSubBlockStart.gif            
dot.gif{
InBlock.gif                
return this.Request.CurrentExecutionFilePath + "?" + ClientQueryString;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gif            
dot.gif{
InBlock.gif                
return this.Request.CurrentExecutionFilePath;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif    
#endregion

InBlock.gif
ContractedSubBlock.gif    
当前执行页面名称。#region 当前执行页面名称。
ExpandedSubBlockStart.gif    
/**//// <summary>
InBlock.gif    
/// 当前执行页面名称。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    protected string PageName
ExpandedSubBlockStart.gif    
dot.gif{
InBlock.gif        
get
ExpandedSubBlockStart.gif        
dot.gif{
InBlock.gif            
string pn = this.Request.CurrentExecutionFilePath;
InBlock.gif            
return pn.Substring(pn.LastIndexOf('/'+ 1);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif    
#endregion

InBlock.gif
ExpandedSubBlockEnd.gif    
#endregion

InBlock.gif
ExpandedBlockEnd.gif}

None.gif


代码丢App_Code文件夹,再在需用调用的页面继承该类就OK了。

 

主要参考文章链接:http://www.cnblogs.com/maple-net/articles/651441.html

转载于:https://www.cnblogs.com/alexworks/articles/1619195.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值