温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:IFNuke1.1.0版源码
当前文件:
IFnuke110/Library/Web/Globals.cs,打开代码结构图
IFnuke110/Library/Web/Globals.cs,打开代码结构图1using System; 2
using System.Collections.Generic; 3
using System.Text; 4
using System.Web; 5
using System.Web.UI; 6
using System.Web.UI.WebControls; 7
8
using IFNuke.BO; 9
using IFNuke.Web.Security; 10
11
namespace IFNuke.Web 12
{ 13
public static class Globals 14
{ 15
public const string DefaultPortalName = "_default"; 16
public const string DefaultPage = "Default.aspx"; 17
18
public const string NoContainer = "Skins/_default/Container/NoContainer.ascx"; 19
public const string DefaultContainer = "Skins/_default/Container/Image Header - Color Background.ascx"; 20
public const string DefaultSkin = "Skins/_default/Horizontal Menu - Fixed Width.ascx"; 21
22
private static string _applicationPath; 23
public static string ApplicationPath 24
{ 25
get 26
{ 27
return _applicationPath; 28
} 29
set 30
{ 31
_applicationPath = value; 32
} 33
} 34
private static string _applicationMapPath; 35
public static string ApplicationMapPath 36
{ 37
get 38
{ 39
return _applicationMapPath; 40
} 41
set 42
{ 43
_applicationMapPath = value; 44
} 45
} 46
47
48
public static HostSetting GetHostSetting() 49
{ 50
return (HostSetting)HttpContext.Current.Application["HostSetting"]; 51
} 52
53
public static Portal GetPortalSetting() 54
{ 55
if (HttpContext.Current.Items["PortalSetting"] == null) 56
{ 57
string portalName = HttpContext.Current.Request.QueryString["PortalName"]; 58
if (!string.IsNullOrEmpty(portalName)) 59
HttpContext.Current.Items["PortalSetting"] = new Portal(portalName); 60
else 61
HttpContext.Current.Items["PortalSetting"] = new Portal(DefaultPortalName); 62
} 63
return (Portal)HttpContext.Current.Items["PortalSetting"]; 64
} 65
66
public static UserBase GetCurrentUser() 67
{ 68
UserBase u = (UserBase)HttpContext.Current.Session["CurrentUser"]; 69
return u; 70
} 71
72
public static void SetCurrentUser(UserBase user) 73
{ 74
HttpContext.Current.Session["CurrentUser"] = user; 75
} 76
77
public static string ResolveUrl(string url) 78
{ 79
// String is Empty, just return Url 80
if (url.Length == 0) 81
{ 82
return url; 83
} 84
85
// String does not contain a ~, so just return Url 86
if (url.StartsWith("~") == false) 87
{ 88
return url; 89
} 90
91
// There is just the ~ in the Url, return the appPath 92
if (url.Length == 1) 93
{ 94
return Globals.ApplicationPath; 95
} 96
97
if (url.ToCharArray()[1] == '/' || url.ToCharArray()[1] == '\\') 98
{ 99
100
// Url looks like ~/ or ~\ 101
if (Globals.ApplicationPath.Length > 1) 102
{ 103
return Globals.ApplicationPath + "/" + url.Substring(2); 104
} 105
else 106
{ 107
return "/" + url.Substring(2); 108
} 109
} 110
else 111
{ 112
113
// Url look like ~something 114
if (Globals.ApplicationPath.Length > 1) 115
{ 116
return Globals.ApplicationPath + "/" + url.Substring(1); 117
} 118
else 119
{ 120
return Globals.ApplicationPath + url.Substring(1); 121
} 122
123
} 124
} 125
126
public static string CreateValidID(string strID) 127
{ 128
string strBadCharacters = " ~./-\\"; 129
int intIndex; 130
for (intIndex = 0; intIndex <= strBadCharacters.Length - 1; intIndex++) 131
{ 132
strID = strID.Replace(strBadCharacters.Substring(intIndex, 1), "_"); 133
} 134
return strID.Replace("__","_").TrimStart('_').TrimEnd('_').ToLower(); 135
} 136
137
public static Control FindControlRecursive(Control objControl, string strControlName) 138
{ 139
if (objControl.Parent == null) 140
{ 141
return null; 142
} 143
else 144
{ 145
if (objControl.Parent.FindControl(strControlName) != null) 146
{ 147
return objControl.Parent.FindControl(strControlName); 148
} 149
else 150
{ 151
return FindControlRecursive(objControl.Parent, strControlName); 152
} 153
} 154
} 155
156
public static Control FindControlRecursiveDown(Control objParent, string strControlName) 157
{ 158
Control objCtl; 159
160
objCtl = objParent.FindControl(strControlName); 161
if (objCtl == null) 162
{ 163
foreach (Control objChild in objParent.Controls) 164
{ 165
objCtl = FindControlRecursiveDown(objChild, strControlName); 166
if (objCtl != null) 167
{ 168
break; 169
} 170
} 171
} 172
return objCtl; 173
} 174
175
public static void SetFckEditorFilePath() 176
{ 177
if (Globals.GetCurrentUser().IsAuthenticated) 178
if (HttpContext.Current.Session["FCKeditor:UserFilesPath"] == null) 179
HttpContext.Current.Session["FCKeditor:UserFilesPath"] = string.Format(HttpContext.Current.Request.ApplicationPath + "/Users/{0}/FCKEditor/", Globals.GetCurrentUser().Name); 180
} 181
182
public static string GetCurrentLanguage() 183
{ 184
if (HttpContext.Current.Items["CurrentLanguage"] == null) 185
{ 186
string defaultLanguage = Globals.GetPortalSetting().DefaultLanguage; 187
HttpContext.Current.Items["CurrentLanguage"] = string.IsNullOrEmpty(defaultLanguage) ? "en-US" : defaultLanguage; 188
} 189
return (string)HttpContext.Current.Items["CurrentLanguage"]; 190
} 191
192
public static void SetCurrentLanguage(string language) 193
{ 194
HttpContext.Current.Items["CurrentLanguage"] = language; 195
} 196
197
198
public static string NavigateUrl() 199
{ 200
return NavigateUrl(Globals.GetPortalSetting().ActiveTab.Id, null); 201
} 202
public static string NavigateUrl(int tabId) 203
{ 204
return NavigateUrl(tabId, null); 205
} 206
public static string NavigateUrl(int tabId, params string[] additionalParameters) 207
{ 208
string url = string.Format("~/Default.aspx?PortalName={0}&TabId={1}", Globals.GetPortalSetting().Name, tabId); 209
if (additionalParameters != null && additionalParameters.Length > 0) 210
{ 211
foreach (string parameter in additionalParameters) 212
if (!string.IsNullOrEmpty(parameter)) 213
url += "&" + parameter; 214
} 215
return url; 216
} 217
} 218
} 219





}
}