📄 communityglobals.cs
字号:
// communities.
//
//*********************************************************************
public static string CacheKey(string key) {
return CommunityID.ToString() + key;
}
//*********************************************************************
//
// ResolveBase Method
//
// Adds the base application path to a relative path.
//
//*********************************************************************
public static string ResolveBase(string relativePath) {
return AppPath + "/" + relativePath;
}
//*********************************************************************
//
// AppPath Property
//
// Represents the path of the current application.
//
//*********************************************************************
public static string AppPath {
get {
if (HttpContext.Current.Request.ApplicationPath == "/")
return String.Empty;
return HttpContext.Current.Request.ApplicationPath;
}
}
//*********************************************************************
//
// GetPageName Method
//
// Removes everything from a request except for the page
// name.
//
//*********************************************************************
public static string GetPageName(string requestPath)
{
// Remove query string
if ( requestPath.IndexOf( '?' ) != -1 )
requestPath = requestPath.Substring( 0, requestPath.IndexOf( '?' ) );
// Remove base path
return requestPath.Remove( 0, requestPath.LastIndexOf( "/" ) );
}
//*********************************************************************
//
// GetSectionPath Method
//
// Removes the page name from a path leaving the
// the path to a community section.
//
//*********************************************************************
public static string GetSectionPath(string requestPath) {
// Remove page name
int slashIndex = requestPath.LastIndexOf("/");
if (slashIndex < requestPath.Length)
requestPath = requestPath.Remove( slashIndex + 1, requestPath.Length - (slashIndex + 1) );
return requestPath;
}
//*********************************************************************
//
// RemovePathInfo Method
//
// Removes the extended information after a page path.
// For example, removes the Web service information after
// the .asmx file name.
//
//*********************************************************************
public static string RemovePathInfo(string requestPath) {
string _pathInfo = HttpContext.Current.Request.PathInfo;
if (_pathInfo.Length == 0)
return requestPath;
return requestPath.Substring(0, requestPath.Length - _pathInfo.Length);
}
//*********************************************************************
//
// ForceLogin Method
//
// Redirects the user to the Login page.
//
//*********************************************************************
public static void ForceLogin() {
HttpContext Context = HttpContext.Current;
Context.Response.Redirect( String.Format( "{0}?ReturnUrl={1}", "Users_Login.aspx", Context.Server.UrlEncode( Context.Request.RawUrl) ) );
}
//*********************************************************************
//
// CalculatePath Method
//
// This method takes a path and replaces the file
// name with a new file name.
//
//*********************************************************************
public static string CalculatePath(string pageName) {
//string rawUrl = HttpContext.Current.Request.RawUrl;
string _rawUrl = ((SectionInfo)HttpContext.Current.Items["SectionInfo"]).Path;
string basePath = _rawUrl.Remove( _rawUrl.LastIndexOf("/"), _rawUrl.Length - _rawUrl.LastIndexOf( "/" ) );
return basePath + "/" + pageName;
}
//*********************************************************************
//
// IsNumeric Method
//
// Since C# doesn't have an IsNumeric function,
// we have to use our own.
//
//*********************************************************************
public static bool IsNumeric(string strInteger) {
try {
int intTemp = Int32.Parse( strInteger );
return true;
} catch (FormatException) {
return false;
}
}
// *********************************************************************
// Configuration Settings Methods
// *********************************************************************
//*********************************************************************
//
// ConnectionString Property
//
// Retrieves database connection string from
// Web.Config file.
//
//*********************************************************************
public static string ConnectionString {
get {
NameValueCollection nvc = (NameValueCollection)
ConfigurationSettings.GetConfig("communityStarterKit/database");
return nvc[ "connectionString" ];
}
}
//*********************************************************************
//
// IspUsername Property
//
// Retrieves the ISP Admin Username from the
// Web.Config file.
//
//*********************************************************************
public static string IspUsername {
get {
NameValueCollection nvc = (NameValueCollection)
ConfigurationSettings.GetConfig("communityStarterKit/Isp");
return nvc[ "IspUsername" ];
}
}
//*********************************************************************
//
// IspPassword Property
//
// Retrieves the ISP Admin Password from the
// Web.Config file.
//
//*********************************************************************
public static string IspPassword {
get {
NameValueCollection nvc = (NameValueCollection)
ConfigurationSettings.GetConfig("communityStarterKit/Isp");
return nvc[ "IspPassword" ];
}
}
//*********************************************************************
//
// EnableServiceTimer Property
//
// Retrieves the enableServiceTimer setting from the Web.Config file.
//
//*********************************************************************
public static bool EnableServiceTimer {
get {
NameValueCollection nvc = (NameValueCollection)
ConfigurationSettings.GetConfig("communityStarterKit/services");
return bool.Parse(nvc[ "enableServiceTimer" ]);
}
}
//*********************************************************************
//
// UrlBasePage Property
//
// Retrieves the path of the community default page from the
// Web.Config file.
//
//*********************************************************************
public static string UrlBasePage {
get {
NameValueCollection nvc = (NameValueCollection)
ConfigurationSettings.GetConfig("communityStarterKit/pagePaths");
return AppPath + nvc[ "basePage" ];
}
}
//*********************************************************************
//
// UrlBaseService Property
//
// Retrieves the path of the community default service from the
// Web.Config file.
//
//*********************************************************************
public static string UrlBaseService {
get {
NameValueCollection nvc = (NameValueCollection)
ConfigurationSettings.GetConfig("communityStarterKit/pagePaths");
return AppPath + nvc[ "baseService" ];
}
}
//*********************************************************************
//
// GetQuotaInfo Method
//
// Retrieves a user's quota information from the database.
//
//*********************************************************************
public static QuotaInfo GetQuotaInfo(string username) {
SqlConnection conPortal = new SqlConnection(ConnectionString);
SqlCommand cmdGet = new SqlCommand("Community_GetQuotaInfo", conPortal);
cmdGet.CommandType = CommandType.StoredProcedure;
cmdGet.Parameters.Add("@communityID", CommunityID);
cmdGet.Parameters.Add("@username", username);
cmdGet.Parameters.Add("@communityQuota", SqlDbType.Int).Direction = ParameterDirection.Output;
cmdGet.Parameters.Add("@communityQuotaUsed", SqlDbType.Int).Direction = ParameterDirection.Output;
cmdGet.Parameters.Add("@userQuota", SqlDbType.Int).Direction = ParameterDirection.Output;
cmdGet.Parameters.Add("@userQuotaUsed", SqlDbType.Int).Direction = ParameterDirection.Output;
conPortal.Open();
cmdGet.ExecuteNonQuery();
QuotaInfo _quotaInfo = new QuotaInfo
(
(int)cmdGet.Parameters["@communityQuota"].Value,
(int)cmdGet.Parameters["@communityQuotaUsed"].Value,
(int)cmdGet.Parameters["@userQuota"].Value,
(int)cmdGet.Parameters["@userQuotaUsed"].Value
);
conPortal.Close();
return _quotaInfo;
}
//*********************************************************************
//
// SmtpServer Property
//
// Retrieves the SMTP Server for the current community
// from the cache or from the database.
//
//*********************************************************************
public static string SmtpServer {
get {
return ((CommunityInfo)HttpContext.Current.Items["CommunityInfo"]).SmtpServer;
}
}
//*********************************************************************
//
// Primary Domain Property
//
// Retrieves the primary domain name associated with this community.
//
//*********************************************************************
public static string PrimaryDomain {
get {
return ((CommunityInfo)HttpContext.Current.Items["CommunityInfo"]).PrimaryDomain;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -