Professional Applications Programmers/Consultants برمجة واستشارات تطبيقات الإنترنت
Skip Navigation LinksHome » Code Library » View

Public general use code classes and xml files that we've compiled and used over the years:

ASP.NET state support functions: Applications, Session, Coockies, Control.

   1:  using System;
   2:  using System.Xml;
   3:  using System.IO;
   4:  using System.Web;
   5:  using System.Web.UI;
   6:   
   7:  namespace Ia.Cl.Model.AspNetState
   8:  {
   9:      ////////////////////////////////////////////////////////////////////////////
  10:   
  11:      /// <summary publish="true">
  12:      /// ASP.NET state support functions: Applications, Session, Coockies, Control.
  13:      /// </summary>
  14:      /// <value>
  15:      /// https://msdn.microsoft.com/en-us/library/z1hkazw7(v=vs.100).aspx
  16:      /// </value>
  17:      /// <remarks> 
  18:      /// Copyright © 2001-2015 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  19:      ///
  20:      /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
  21:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  22:      ///
  23:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  24:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  25:      /// 
  26:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  27:      /// 
  28:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  29:      /// </remarks> 
  30:      public class View
  31:      {
  32:          public View() { }
  33:   
  34:          public static void Write(StateBag viewState, string name, object value)
  35:          {
  36:              viewState[name] = value;
  37:          }
  38:   
  39:          public static object Read(StateBag viewState, string name)
  40:          {
  41:              return viewState[name];
  42:          }
  43:      }
  44:   
  45:      ////////////////////////////////////////////////////////////////////////////
  46:      ////////////////////////////////////////////////////////////////////////////
  47:   
  48:   
  49:   
  50:   
  51:   
  52:   
  53:      ////////////////////////////////////////////////////////////////////////////
  54:      ////////////////////////////////////////////////////////////////////////////
  55:   
  56:      /// <summary>
  57:      ///
  58:      /// </summary>
  59:      public class Control
  60:      {
  61:          public Control() { }
  62:      }
  63:   
  64:      ////////////////////////////////////////////////////////////////////////////
  65:      ////////////////////////////////////////////////////////////////////////////
  66:   
  67:   
  68:   
  69:   
  70:   
  71:   
  72:      ////////////////////////////////////////////////////////////////////////////
  73:      ////////////////////////////////////////////////////////////////////////////
  74:   
  75:      /// <summary>
  76:      ///
  77:      /// </summary>
  78:      public class Cookie
  79:      {
  80:          ////////////////////////////////////////////////////////////////////////////
  81:   
  82:          /// <summary>
  83:          ///
  84:          /// </summary>
  85:          public Cookie() { }
  86:   
  87:          ////////////////////////////////////////////////////////////////////////////
  88:   
  89:          /// <summary>
  90:          ///
  91:          /// </summary>
  92:          public static void Write(string name, string value)
  93:          {
  94:              Write(name, value, 9999);
  95:          }
  96:   
  97:          ////////////////////////////////////////////////////////////////////////////
  98:   
  99:          /// <summary>
 100:          ///
 101:          /// </summary>
 102:          public static void Write(string name, string value, int lifeInDays)
 103:          {
 104:              // this appends a cookie to the collection
 105:   
 106:              HttpCookie cookie = new HttpCookie(name, value);
 107:   
 108:              cookie.Expires = DateTime.UtcNow.AddHours(3 + 24 * lifeInDays);
 109:   
 110:              HttpContext.Current.Response.Cookies.Add(cookie);
 111:          }
 112:   
 113:          ////////////////////////////////////////////////////////////////////////////
 114:   
 115:          /// <summary>
 116:          ///
 117:          /// </summary>
 118:          public static string Read(string name)
 119:          {
 120:              // this reads the value of the cookie
 121:              string value;
 122:              HttpCookie cookie;
 123:   
 124:              cookie = HttpContext.Current.Request.Cookies[name];
 125:   
 126:              if (cookie == null) value = null;
 127:              else value = cookie.Value;
 128:   
 129:              return value;
 130:          }
 131:   
 132:          ////////////////////////////////////////////////////////////////////////////
 133:          ////////////////////////////////////////////////////////////////////////////
 134:   
 135:   
 136:   
 137:   
 138:   
 139:   
 140:   
 141:   
 142:          ////////////////////////////////////////////////////////////////////////////
 143:          ////////////////////////////////////////////////////////////////////////////
 144:   
 145:          /// <summary>
 146:          ///
 147:          /// </summary>
 148:          public class Application
 149:          {
 150:              public Application() { }
 151:          }
 152:   
 153:          ////////////////////////////////////////////////////////////////////////////
 154:          ////////////////////////////////////////////////////////////////////////////
 155:   
 156:   
 157:   
 158:   
 159:   
 160:   
 161:          ////////////////////////////////////////////////////////////////////////////
 162:          ////////////////////////////////////////////////////////////////////////////
 163:   
 164:          /// <summary>
 165:          ///
 166:          /// </summary>
 167:          public class Session
 168:          {
 169:              public Session() { }
 170:          }
 171:   
 172:          ////////////////////////////////////////////////////////////////////////////
 173:          ////////////////////////////////////////////////////////////////////////////
 174:   
 175:      }
 176:  }