zoukankan      html  css  js  c++  java
  • ASP.NET 开发, PageBase, ModuleBase

    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; }
            }

        }

    }
  • 相关阅读:
    [JSOI2007][BZOJ1030] 文本生成器|AC自动机|动态规划
    [NOI2014][BZOJ3670] 动物园|KMP
    [HAOI2010][BZOJ2427] 软件安装|tarjan|树型dp
    [JSOI2008][BZOJ1017] 魔兽地图DotR|树型dp
    [JLOI2014][BZOJ3631] 松鼠的新家|树上倍增LCA|差分
    [SDOI2010][BZOJ1975] 魔法猪学院|A*|K短路
    [BZOJ1251] 序列终结者|Splay
    hdu 2141 Can you find it?
    hdu 3152 Obstacle Course
    hdu 2680 Choose the best route
  • 原文地址:https://www.cnblogs.com/hcfalan/p/500752.html
Copyright © 2011-2022 走看看