SystemInfo
Overview
The SystemInfo class provides static access to system-wide information, user context, configuration settings, and logging capabilities. This class serves as a central point for accessing user authentication details, company preferences, localization settings, and various system utilities.
Property Reference Table
| Property | Type | Access | Description |
|---|
Company | Preference | Get | Returns the company/organization preferences and settings |
IsAdminUser | bool | Get | Indicates whether the current user is an administrator |
IsCustomerUser | bool | Get | Indicates whether the current user is a customer user |
IsGuestUser | bool | Get | Indicates whether the current user is a guest user |
IsInternalUser | bool | Get | Indicates whether the current user is an internal employee |
IsPartnerUser | bool | Get | Indicates whether the current user is a partner user |
IsPortalUser | bool | Get | Indicates whether the current user is a portal user |
UserDevice | DeviceInfo | Get | Returns device information for the current user's client |
UserInfo | dynamic | Get | Returns the current user as a dynamic object |
UserId | string | Get | Returns the current user's ID or guest ID if not authenticated |
Method Reference Table
| Method | Return Type | Description |
|---|
Culture() | CultureInfo | Returns the culture information for the current user interface |
CurrencyCulture() | CultureInfo | Returns the currency culture for the logged-in user |
Debug(string, params object[]) | void | Writes a debug message to the event log |
Error(string, params object[]) | void | Writes an error message to the event log |
Error(Exception) | void | Logs an exception to the event log |
GetUserUrl(SUser) | string | Retrieves the URL associated with a user's portal or organization |
Info(string, params object[]) | void | Writes an informational message to the event log |
IsMultiCurrencyEnabled() | bool | Checks if multi-currency support is enabled |
UICulture() | CultureInfo | Returns the UI culture information for the logged-in user |
Warning(string, params object[]) | void | Writes a warning message to the event log |
Properties
Company
public static Preference Company { get; }
Returns the company/organization preferences and settings.
Returns:Preference - The company preference object
IsAdminUser
public static bool IsAdminUser { get; }
Indicates whether the current user is an administrator user.
Returns:bool - true if the user is an administrator; otherwise, false
IsCustomerUser
public static bool IsCustomerUser { get; }
Indicates whether the current user is a customer user.
Returns:bool - true if the user has a customer role type; otherwise, false
IsGuestUser
public static bool IsGuestUser { get; }
Indicates whether the current user is a guest user.
Returns:bool - true if the user is a guest user; otherwise, false
IsInternalUser
public static bool IsInternalUser { get; }
Indicates whether the current user is an internal employee user.
Returns:bool - true if the user has an employee role type; otherwise, false
IsPartnerUser
public static bool IsPartnerUser { get; }
Indicates whether the current user is a partner user.
Returns:bool - true if the user is a partner user; otherwise, false
IsPortalUser
public static bool IsPortalUser { get; }
Indicates whether the current user is a portal user.
Returns:bool - true if the user is a portal user; otherwise, false
UserDevice
public static IDevice UserDevice { get; }
Returns device information for the current user's client.
Returns:DeviceInfo - Device information object
UserId
public static string UserId { get; }
Returns the current user's ID. If no authenticated user exists, returns the guest user ID. This property safely handles null-reference scenarios.
Returns:string - The current user ID or guest ID
UserInfo
public static dynamic UserInfo { get; }
Returns the current user as a dynamic object for flexible property access.
Returns:dynamic - The current user cast as dynamic
Methods
Culture
public static System.Globalization.CultureInfo Culture()
Returns the culture information for the current user based on their locale setting.
Returns:CultureInfo - Culture information for the user
Usage:
var culture = SystemInfo.Culture();
SystemInfo.Debug($"User culture: {culture.Name}");
CurrencyCulture
public static System.Globalization.CultureInfo CurrencyCulture()
Returns the culture information for formatting currency values for the logged-in user. This is distinct from the currency symbol and respects multi-currency configuration.
Returns:CultureInfo - Currency culture information
Usage:
var currencyCulture = SystemInfo.CurrencyCulture();
decimal amount = 1234.56m;
string formatted = amount.ToString("C", currencyCulture);
💡 Note: If multi-currency is enabled, this returns the user's general culture. Otherwise, it returns the user's specific locale or the organization's currency culture.
Debug
public static void Debug(string message, params object[] args)
Writes a debug-level message to the event log.
Parameters:
message (string) - The debug message or format stringargs (params object[]) - Optional format arguments
Usage:
SystemInfo.Debug("Processing user request for UserID: {0}", userId);
Error (Exception)
public static void Error(Exception ex)
Logs an exception to the event log.
Parameters:
ex (Exception) - The exception to log
Usage:
try
{
// Code that may throw exception
}
catch (Exception ex)
{
SystemInfo.Error(ex);
}
Error (Message)
public static void Error(string message, params object[] args)
Writes an error-level message to the event log.
Parameters:
message (string) - The error message or format stringargs (params object[]) - Optional format arguments
Usage:
SystemInfo.Error("Failed to process transaction: {0}", errorDetails);
GetUserUrl
public static string GetUserUrl(SUser user = null)
Retrieves the base URL for a user, considering their portal assignment. If the user is assigned to a Custom Hub, it returns the portal URL; otherwise, returns the organization URL.
Parameters:
user (SUser, optional) - The user to retrieve the URL for. If null, uses the current user.
Returns:string - The user's portal or organization URL with appropriate SSL protocol
Usage:
// Get current user's URL
string currentUserUrl = SystemInfo.GetUserUrl();
// Get specific user's URL
SUser specificUser = GetUser(userId);
string userUrl = SystemInfo.GetUserUrl(specificUser);
💡 Note: The method automatically applies SSL protocol (https://) if SSL is enabled for the user's portal or organization.
Info
public static void Info(string message, params object[] args)
Writes an informational message to the event log.
Parameters:
message (string) - The informational message or format stringargs (params object[]) - Optional format arguments
Usage:
SystemInfo.Info("User {0} logged in successfully", userName);
IsMultiCurrencyEnabled
public static bool IsMultiCurrencyEnabled()
Checks if multi-currency support is enabled at the company level.
Returns:bool - true if multi-currency is enabled; otherwise, false
Usage:
if (SystemInfo.IsMultiCurrencyEnabled())
{
// Display currency selector
}
UICulture
public static System.Globalization.CultureInfo UICulture()
Returns the UI culture for the logged-in user. Falls back to the company's language setting if the user locale is not specified.
Returns:CultureInfo - UI culture information
Usage:
var uiCulture = SystemInfo.UICulture();
Console.WriteLine($"UI Language: {uiCulture.DisplayName}");
Warning
public static void Warning(string message, params object[] args)
Writes a warning-level message to the event log.
Parameters:
message (string) - The warning message or format stringargs (params object[]) - Optional format arguments
Usage:
SystemInfo.Warning("Unusual activity detected for UserID: {0}", userId);
Usage Examples
Example 1: User Authentication Check
// Check if user is authenticated and has appropriate role
if (!SystemInfo.IsGuestUser)
{
if (SystemInfo.IsAdminUser)
{
// Admin-specific functionality
SystemInfo.Debug($"Welcome Admin: {SystemInfo.User.DisplayName}");
}
else if (SystemInfo.IsPartnerUser)
{
// Partner-specific functionality
SystemInfo.Debug($"Welcome Partner: {SystemInfo.User.DisplayName}");
}
}
else
{
// Redirect to login
}
Example 2: Localization and Formatting
// Format currency according to user settings
var culture = SystemInfo.CurrencyCulture();
decimal totalAmount = 1250.75m;
string formattedAmount = totalAmount.ToString("C", culture);
Example 3: Logging and Debugging
try
{
// Business logic
SystemInfo.Info("Starting order processing for Order ID: {0}", orderId);
ProcessOrder(orderId);
SystemInfo.Info("Order processed successfully");
}
catch (ValidationException vex)
{
SystemInfo.Warning("Validation failed: {0}", vex.Message);
throw;
}
catch (Exception ex)
{
SystemInfo.Error(ex);
throw;
}
Best Practices
Null Safety: Many properties check for null users before accessing role information. Always verify SystemInfo.User is not null for custom logic.
Guest User Handling: Use SystemInfo.IsGuestUser to determine if a user is authenticated before accessing user-specific features.
Logging Levels: Use appropriate logging methods:
Debug() - Development and troubleshootingInfo() - Normal operation eventsWarning() - Unexpected but handled situationsError() - Errors and exceptions
Culture Information: Always use SystemInfo.CurrencyCulture() for currency formatting and SystemInfo.UICulture() for localized UI text.
Portal Context: When building URLs or determining configuration, use portal-aware methods like GetUserUrl() which automatically handle portal vs. company context.
Performance: Properties like User access cached data for optimal performance.
Thread Safety
The SystemInfo class accesses HttpContext.Current for request-specific information. Methods and properties are safe to use within the context of a web request but should not be called from background threads without an active HTTP context.