using System;
using System.Web;
namespace admin
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// Utility 的摘要说明。
/// </summary>
public class Utility
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
public Utility()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static string GetRequestString(HttpRequest req,string val)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string[] arr = req.QueryString.GetValues(val);
if(arr == null)
arr = req.Form.GetValues(val);
if(arr != null)
return arr[0];
else
return null;
}
public static int GetRequestInt(HttpRequest req,string val)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string[] arr = req.QueryString.GetValues(val);
if(arr == null)
arr = req.Form.GetValues(val);
if(arr != null)
return StringToInt(arr[0]);
else
return 0;
}
public static string GetCookiesString(HttpRequest req,string CookiesName)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(req.Cookies[CookiesName] != null)
return req.Cookies[CookiesName].Value;
else
return null;
}
public static int GetCookiesInt(HttpRequest req,string CookiesName)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(req.Cookies[CookiesName] != null)
return StringToInt(req.Cookies[CookiesName].Value);
else
return 0;
}
public static bool SetCookies(HttpResponse res,string cookname,int cookval)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
HttpCookie cook = new HttpCookie(cookname,cookval.ToString());
res.Cookies.Add(cook);
return true;
}
catch
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return false;
}
}
public static bool SetCookies(HttpResponse res,string cookname,string cookval)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
HttpCookie cook = new HttpCookie(cookname,cookval);
res.Cookies.Add(cook);
return true;
}
catch
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return false;
}
}
private static int StringToInt(string val)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return Int32.Parse(val);
}
catch
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return 0;
}
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
posted on
2007-04-07 11:10
niugm
阅读(
561)
评论()
编辑
收藏
举报