温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:云南工艺品网前台源码
当前文件:
ArtsAndCrafts/ArtsAndCrafts/App_Code/CommonClass.cs[6K,2009-6-12 11:31:42],打开代码结构图
ArtsAndCrafts/ArtsAndCrafts/App_Code/CommonClass.cs[6K,2009-6-12 11:31:42],打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Web; 5
using System.Web.Security; 6
using System.Web.UI; 7
using System.Web.UI.WebControls; 8
using System.Web.UI.WebControls.WebParts; 9
using System.Web.UI.HtmlControls; 10
using System.Text; 11
using System.Text.RegularExpressions; 12
using System.Runtime.InteropServices; 13
using System.Management; 14
//该源码下载自www.51aspx.com(51aspx.com) 15
16
/// <summary> 17
///CommonClass 的摘要说明 18
/// </summary> 19
public class CommonClass 20
{ 21
/// <summary> 22
/// 提示信息并页面跳转 23
/// </summary> 24
/// <param name="MessageString"></param> 25
/// <param name="RedirectUrl"></param> 26
public static void MessageAndRedirect(string MessageString, string RedirectUrl) 27
{ 28
System.Web.HttpContext.Current.Response.Write("<script type='text/javascript'>alert('" + MessageString + "');top.location.href='" + RedirectUrl + "'</script>"); 29
} 30
31
/// <summary> 32
/// 提示信息 33
/// </summary> 34
/// <param name="MessageString"></param> 35
public static void Message(string MessageString) 36
{ 37
System.Web.HttpContext.Current.Response.Write("<script type='text/javascript'>alert('" + MessageString + "');</script>"); 38
} 39
40
/// <summary> 41
/// 获取当前页面的URL 42
/// </summary> 43
public static string GetCurrentUrl() 44
{ 45
return System.Web.HttpContext.Current.Request.Url.AbsoluteUri.ToString(); 46
} 47
48
49
50
/// <summary> 51
/// 返回上一页面 52
/// </summary> 53
public static void GoBack() 54
{ 55
System.Web.HttpContext.Current.Response.Write("<script type='text/javascript'>history.go(-2);</script>"); 56
} 57
58
/// <summary> 59
/// 关闭本窗口 60
/// </summary> 61
public static void CloseWin() 62
{ 63
System.Web.HttpContext.Current.Response.Write("<script type='text/javascript'>window.opener=null;window.close();</script>"); 64
} 65
66
/// <summary> 67
/// 提示并返回上一个页面 68
/// </summary> 69
/// <param name="MessageString"></param> 70
public static void MessageAndGoBack(string MessageString) 71
{ 72
System.Web.HttpContext.Current.Response.Write("<script type='text/javascript'>alert('" + MessageString + "');history.go(-1);</script>"); 73
} 74
75
/// <summary> 76
/// 密码MD5加密 77
/// </summary> 78
/// <param name="str"></param> 79
/// <returns></returns> 80
public static string Md5(string str) 81
{ 82
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16); 83
84
} 85
/// <summary> 86
/// 产生用户找回密码验证码 87
/// </summary> 88
/// <returns></returns> 89
public static string GetValidate() 90
{ 91
string wordstr = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 92
char[] wordchar = wordstr.ToCharArray(); 93
94
Random rd = new Random(); 95
string rdpwd = string.Empty; 96
for (int i = 0; i < 6; i++) 97
{ 98
int rdnum = rd.Next(62); 99
rdpwd += wordchar[rdnum]; 100
} 101
return rdpwd; 102
} 103
104
/// <summary> 105
/// 获取客户端IP 106
/// </summary> 107
/// <returns></returns> 108
public static string GetClientIP() 109
{ 110
string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; 111
if (null == result || result == String.Empty) 112
{ 113
result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; 114
} 115
116
if (null == result || result == String.Empty) 117
{ 118
result = HttpContext.Current.Request.UserHostAddress; 119
} 120
return result; 121
} 122
123
/// <summary> 124
/// 获取客户端MAC 125
/// </summary> 126
/// <param name="IP"></param> 127
/// <returns></returns> 128
[DllImport("Iphlpapi.dll")] 129
private static extern int SendARP(Int32 dest, Int32 host, ref Int64 mac, ref Int32 length); 130
[DllImport("Ws2_32.dll")] 131
private static extern Int32 inet_addr(string ip); 132
public static string GetMAC() 133
{ 134
// 在此处放置用户代码以初始化页面 135
try 136
{ 137
string strClientIP = HttpContext.Current.Request.UserHostAddress.ToString().Trim(); 138
Int32 ldest = inet_addr(strClientIP); //目的地的ip 139
Int32 lhost = inet_addr(""); //本地服务器的ip 140
Int64 macinfo = new Int64(); 141
Int32 len = 6; 142
int res = SendARP(ldest, 0, ref macinfo, ref len); 143
string mac_src = macinfo.ToString("X"); 144
if (mac_src == "0") 145
{ 146
if (strClientIP == "127.0.0.1") 147
{ 148
return GetlMAC(); 149
} 150
} 151
while (mac_src.Length < 12) 152
{ 153
mac_src = mac_src.Insert(0, "0"); 154
} 155
156
string mac_dest = ""; 157
158
for (int i = 0; i < 11; i++) 159
{ 160
if (0 == (i % 2)) 161
{ 162
if (i == 10) 163
{ 164
mac_dest = mac_dest.Insert(0, mac_src.Substring(i, 2)); 165
} 166
else 167
{ 168
mac_dest = "-" + mac_dest.Insert(0, mac_src.Substring(i, 2)); 169
} 170
} 171
} 172
173
return mac_dest; 174
} 175
catch (Exception err) 176
{ 177
return err.Message; 178
} 179
} 180
181
/// <summary> 182
/// 获取本机MAC 183
/// </summary> 184
/// <returns></returns> 185
protected static string GetlMAC() 186
{ 187
string stringMAC = ""; 188
ManagementClass MC = new ManagementClass("Win32_NetworkAdapterConfiguration"); 189
ManagementObjectCollection MOC = MC.GetInstances(); 190
191
foreach (ManagementObject MO in MOC) 192
{ 193
if ((bool)MO["IPEnabled"] == true) 194
{ 195
stringMAC += MO["MACAddress"].ToString(); 196
} 197
} 198
stringMAC = stringMAC.ToString().Replace(":", "-"); 199
return stringMAC; 200
} 201
202
} 203








