110,538
社区成员
发帖
与我相关
我的任务
分享
int Num = CommonRequest.GetUserLoginTimes(user)
代码:
public class CommonRequest//通用
{
public static int GetUserLoginTimes(User user)//static
{
return User.Type == "admin"?ServiceFactory.GetFactory().GetUserService().GetUserLoginTimes(User.userId):0;
}
}
UserRequest ur = new UserRequest();//new
int Num = ur.GetUserLoginTimes(user)
代码:
public class UserRequest//独立类
{
public int GetUserLoginTimes(User user)
{
return User.Type == "admin"?ServiceFactory.GetFactory().GetUserService().GetUserLoginTimes(User.userId):0;
}
}
public class ComUtils
{
public static string GetCookieStr(string s)//获得cookie值
{
HttpCookie c = HttpContext.Current.Request.Cookies[s];
return c == null ? "" : c.Value;
}
public static string GetMd5(string s)//获得md5密文
{
MD5 md5 = new MD5();//实例
return string.IsNullOrEmpty(s) ? "" : md5.GetMD5(s);
}
public static string GetReferrer//获得UrlReferrer
{
get
{
Uri Uri = HttpContext.Current.Request.UrlReferrer;
return Uri == null ? "" : Uri.Host.ToString();
}
}
public static string GetUrlTokenDecode(string s)//获得UrlTokenDecode
{
try
{
return string.IsNullOrEmpty(s) ? "" : Encoding.Default.GetString(HttpServerUtility.UrlTokenDecode(s));
}
catch { log4net.Error("GetTokenDecode, s=" + s); return ""; }
}
}
这种适合用static么,又比如获取客户端IP这种使用量巨大,没个用户过来第一件事就是拿IP,
public static string GetIPAddress()
{
string s = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (string.IsNullOrEmpty(s))
{
s = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
if (string.IsNullOrEmpty(s))
{
s = HttpContext.Current.Request.UserHostAddress;
}
if (string.IsNullOrEmpty(s))
{
return "";
}
return s;
}
这样的合适用static不