会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
ALAN (企业即时沟通)
导航
博客园
首页
新随笔
联系
订阅
管理
公告
ASP.NET 开发, PageBase, ModuleBase
Posted on
2006-09-11 11:03
hcfalan
阅读(
503
) 评论(
0
)
编辑
收藏
举报
using
System;
using
System.Web.UI;
public
class
ApplicationConfiguration : IConfigurationSectionHandler
{
public
Object Create(Object parent,
object
configContext, XmlNode section)
{
//
}
public
static
void
OnApplicationStart(String myAppPath)
{
appRoot
=
myAppPath;
//
init ApplicationConfiguration & call it's Create message
System.Configuration.ConfigurationSettings.GetConfig(
"
ApplicationConfiguration
"
);
}
}
public
class
Global : System.Web.HttpApplication
{
protected
void
Application_Start(Object sender, EventArgs e)
{
//
do something at Application Start
ApplicationConfiguration.OnApplicationStart(Context.Server.MapPath(Context.Request.ApplicationPath));
}
}
/**/
///
<summary>
///
All pages base class
///
</summary>
public
class
PageBase : Page
{
public
const
String KEY_CACHEUSER
=
"
Cache::User
"
;
private
static
String pageSecureUrlBase;
//
for securite http, that is: https
private
static
String pageUrlBase;
private
static
String urlSuffix;
public
PageBase()
{
try
{
string
strPort
=
(Context.Request.Url.Port
==
80
?
""
: String.Format(
"
:{0}
"
, Context.Request.Url.Port));
string
strApp
=
(Context.Request.ApplicationPath
==
"
/
"
?
""
: Context.Request.ApplicationPath);
this
.urlSuffix
=
Context.Request.Url.Host
+
strPort
+
strApp;
this
.pageUrlBase
=
@"
http://
"
+
urlSuffix;
}
catch
{
//
for design time
}
}
public
static
String UrlBase
{
get
{
return
pageUrlBase; }
}
public
UserInfo SignInUser
{
get
{
try
{
return
(UserInfo)Session[KEY_CACHEUSER]; }
catch
{
return
null
;
/**/
/*
for design time
*/
}
}
set
{
if
(
null
==
value)
{ Session.Remove(KEY_CACHEUSER); }
else
{ Session[KEY_CACHEUSER]
=
value; }
}
}
protected
override
void
OnError(EventArgs e)
{
//
todo your error handle code here
//
..
//
and determind if call base OnError message or not
//
base.OnError(e);
}
}
/**/
///
<summary>
///
All user controls base class
///
</summary>
public
class
ModuleBase : UserControl
{
private
String basePathPrefix;
public
String PathPrefix
{
get
{
if
(
null
==
basePathPrefix)
{ basePathPrefix
=
PageBase.UrlBase; }
return
basePathPrefix;
}
set
{
basePathPrefix
=
value;
}
}
public
UserInfo SignInUser
{
get
{
try
{
return
(UserInfo)Session[PageBase.KEY_CACHEUSER]; }
catch
{
return
null
;
/**/
/*
for design time
*/
}
}
set
{
if
(
null
==
value)
{ Session.Remove(PageBase.KEY_CACHEUSER); }
else
{ Session[PageBase.KEY_CACHEUSER]
=
value; }
}
}
}
会员力量,点亮园子希望
刷新页面
返回顶部
Powered by:
博客园
Copyright © 2024 hcfalan
Powered by .NET 8.0 on Kubernetes