学习微软企业库存心得--总结
1:asp.net页面可以继承基类,可以把页面里中的页面加载事件与报错,日志等事件都写进基类,方便每个页面的登陆与共同的方法处理。
例如基类:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Diagnostics; using Microsoft.Practices.EnterpriseLibrary.Common.Configuration; using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling; using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration; using Microsoft.Practices.EnterpriseLibrary.Logging; namespace EntLibStudy.Helper { public class BasePage : System.Web.UI.Page { private bool _isLogin; public bool IsLogin { get { return _isLogin; } private set { _isLogin = value; } } private string _userName; public string UserName { get { return _userName; } private set { _userName = value; } } private bool _isAdmin; public bool IsAdmin { get { return _isAdmin; } private set { _isAdmin = value; } } protected void Page_Load(object sender, EventArgs e) { this.UserName = Utils.GetCookies("uid"); var a = Utils.GetCookies("sid"); if (string.IsNullOrEmpty(this.UserName) == false) { this.IsLogin = true; this.IsAdmin = Utils.GetCookies("isadmin") == "1" ? true : false; } ShowPage(); } protected void Page_Error(object sender, EventArgs e) { var ex = Server.GetLastError(); HandleException(ex, "ExceptionPolicy"); Server.ClearError(); } protected void HandleException(Exception ex, string policy) { bool rethrow = false; var exManager = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>(); rethrow = exManager.HandleException(ex, policy); if (rethrow) { this.RedirectPermanent("~/error.aspx"); } } /// <summary> /// 展示子页面,可被子页面重写 /// </summary> protected virtual void ShowPage() { //TODO 具体的业务逻辑 } /// <summary> /// 永久重定向 /// </summary> /// <param name="url"></param> protected void RedirectPermanent(string url) { Response.RedirectPermanent(url); } } }
子页面的代码引用
using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace EntLibStudy.WEB { public partial class _Default : Helper.BasePage { protected override void ShowPage() { base.ShowPage(); } } }
2:winfrom的窗体可以继承winfrom窗体,把共同的窗体所使用的相同的界面做一个可以继承的父窗体。 例如: ChangePwd 与Form1,NewUser,ResetPwd都继承UserDialogBase 例如打开一个Newuser窗体时, UserDialogBase f = new NewUser(); f.ShowDialog();
加密主要代码:
Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll 然后再需要的地方加入 using Microsoft.Practices.EnterpriseLibrary.Security.Cryptography; 下面是主要的加密解密代码 //加密 string Encrypt = Cryptographer.EncryptSymmetric("RC2CryptoServiceProvider", str); //解密 string Encrypt = Cryptographer.DecryptSymmetric("RC2CryptoServiceProvider", str);
学习地址:http://blog.sina.com.cn/s/blog_94b91f620100xnpv.html