关于数据库和字符操作的公共类的网址如下:
http://www.bc-cn.net/bbs/dispbbs.asp?BoardID=113&ID=30050
以下是后加入的,关于cookie和session的处理,及提取页面提交内容的处理:
页面提交内容是提交过来个数组,然后根据数组内容获得提交的数据
using System; using System.Web;
namespace PublicClass { /// <summary> /// PageControl 的摘要说明。 /// </summary> public class PageControl { public PageControl() { // // TOD 在此处添加构造函数逻辑 // } private string TempReturnString = ""; //读取Cookie值 public string GetCookie(string CookieName) { string hcstr = ""; try { if (HttpContext.Current.Request.Cookies[CookieName] != null) { hcstr = HttpContext.Current.Request.Cookies[CookieName].Value.ToString(); } } catch (Exception ex) { hcstr = null; SetErrorInfo(ex.Message); MyException me = new MyException(TempReturnString); throw me; } return hcstr; } //设置Cookie值,并从不过期 public void SetCookie(string CookieName,string CookieValue) { try { HttpCookie hc = new HttpCookie(CookieName); hc.Value = CookieValue; hc.Expires = DateTime.MaxValue; HttpContext.Current.Response.Cookies.Add(hc); } catch (Exception ex) { SetErrorInfo(ex.Message); MyException me = new MyException(TempReturnString); throw me; } } //读Session public string GetSession(string SessionName) { string hcstr = ""; try { if (HttpContext.Current.Session[SessionName] != null) { hcstr = HttpContext.Current.Session[SessionName].ToString(); } } catch (Exception ex) { hcstr = null; SetErrorInfo(ex.Message); MyException me = new MyException(TempReturnString); throw me; } return hcstr; } //设置Cookie值,并从不过期 public void SetSession(string SessionName,string SessionValue) { try { HttpContext.Current.Session[SessionName] = SessionValue; } catch (Exception ex) { SetErrorInfo(ex.Message); MyException me = new MyException(TempReturnString); throw me; } }
//取得form提交过来的值 GetFlag=1 表示method=post GetFlag=2 表示method=get public string[] GetFormPostValue(string[] FormValueArray,int GetFlag) { string[] TempValueArray; try { TempValueArray= new string[FormValueArray.Length]; for (int i=0;i<FormValueArray.Length;i++) { StrControl sc = new StrControl(); if (GetFlag == 1) { TempValueArray[i] = sc.ReplaceString(HttpContext.Current.Request.Form[FormValueArray[i]]); } else { TempValueArray[i] = sc.ReplaceString(HttpContext.Current.Request.Params[FormValueArray[i]]); } } } catch (Exception ex) { TempValueArray = null; SetErrorInfo(ex.Message); MyException me = new MyException(TempReturnString); throw me; } return TempValueArray; }
private void SetErrorInfo(string errstr) { Public_Class pc = new Public_Class(); TempReturnString = pc.SetErrorInfo(errstr); } } }