2012-07-28 00:13:06 +06:00
using System ;
using System.Collections.Generic ;
using System.Configuration ;
2012-09-13 09:00:21 +07:00
using System.Linq ;
2017-05-24 19:01:01 +10:00
using System.Net.Configuration ;
2012-07-28 00:13:06 +06:00
using System.Web ;
using System.Web.Configuration ;
2013-06-21 16:20:18 +10:00
using System.Web.Hosting ;
2012-11-14 03:32:50 +05:00
using System.Web.Routing ;
2014-02-26 02:57:05 +11:00
using System.Web.Security ;
2012-07-28 00:13:06 +06:00
using System.Xml ;
2012-10-06 18:46:12 -02:00
using System.Xml.Linq ;
2014-02-22 16:44:02 +01:00
using System.Xml.XPath ;
2012-07-28 00:13:06 +06:00
using Umbraco.Core.IO ;
2012-08-06 22:40:06 +06:00
using Umbraco.Core.Logging ;
2014-02-26 02:57:05 +11:00
using Umbraco.Core.Security ;
2012-07-28 00:13:06 +06:00
namespace Umbraco.Core.Configuration
{
2012-12-31 12:15:46 -01:00
//NOTE: Do not expose this class ever until we cleanup all configuration including removal of static classes, etc...
// we have this two tasks logged:
// http://issues.umbraco.org/issue/U4-58
// http://issues.umbraco.org/issue/U4-115
//TODO: Replace checking for if the app settings exist and returning an empty string, instead return the defaults!
2012-08-09 07:41:13 +06:00
2012-07-28 00:13:06 +06:00
/// <summary>
/// The GlobalSettings Class contains general settings information for the entire Umbraco instance based on information from web.config appsettings
/// </summary>
internal class GlobalSettings
{
2012-08-06 22:40:06 +06:00
2012-07-28 00:13:06 +06:00
#region Private static fields
2012-11-26 10:07:08 -01:00
private static Version _version ;
2013-02-27 20:42:11 +06:00
private static readonly object Locker = new object ( ) ;
//make this volatile so that we can ensure thread safety with a double check lock
private static volatile string _reservedUrlsCache ;
2012-07-28 00:13:06 +06:00
private static string _reservedPathsCache ;
2015-10-20 09:48:58 +02:00
private static HashSet < string > _reservedList = new HashSet < string > ( ) ;
2013-02-27 23:02:12 +06:00
private static string _reservedPaths ;
private static string _reservedUrls ;
//ensure the built on (non-changeable) reserved paths are there at all times
private const string StaticReservedPaths = "~/app_plugins/,~/install/," ;
2014-02-26 04:15:14 +11:00
private const string StaticReservedUrls = "~/config/splashes/booting.aspx,~/config/splashes/noNodes.aspx,~/VSEnterpriseHelper.axd," ;
2012-07-28 00:13:06 +06:00
#endregion
2012-12-31 12:15:46 -01:00
/// <summary>
2013-03-12 12:02:04 -01:00
/// Used in unit testing to reset all config items that were set with property setters (i.e. did not come from config)
2013-02-27 22:35:27 +06:00
/// </summary>
2013-03-12 12:02:04 -01:00
private static void ResetInternal ( )
2013-02-27 22:35:27 +06:00
{
_reservedUrlsCache = null ;
2013-02-27 23:02:12 +06:00
_reservedPaths = null ;
_reservedUrls = null ;
2017-05-24 19:01:01 +10:00
HasSmtpServer = null ;
2013-02-27 22:35:27 +06:00
}
2013-03-12 12:02:04 -01:00
/// <summary>
/// Resets settings that were set programmatically, to their initial values.
/// </summary>
/// <remarks>To be used in unit tests.</remarks>
internal static void Reset ( )
{
ResetInternal ( ) ;
}
2017-05-24 19:01:01 +10:00
public static bool HasSmtpServerConfigured ( string appPath )
{
if ( HasSmtpServer . HasValue ) return HasSmtpServer . Value ;
var config = WebConfigurationManager . OpenWebConfiguration ( appPath ) ;
var settings = ( MailSettingsSectionGroup ) config . GetSectionGroup ( "system.net/mailSettings" ) ;
if ( settings = = null | | settings . Smtp = = null ) return false ;
if ( settings . Smtp . SpecifiedPickupDirectory ! = null & & string . IsNullOrEmpty ( settings . Smtp . SpecifiedPickupDirectory . PickupDirectoryLocation ) = = false )
return true ;
if ( settings . Smtp . Network ! = null & & string . IsNullOrEmpty ( settings . Smtp . Network . Host ) = = false )
return true ;
return false ;
}
/// <summary>
/// For testing only
/// </summary>
internal static bool? HasSmtpServer { get ; set ; }
/// <summary>
2012-07-28 00:13:06 +06:00
/// Gets the reserved urls from web.config.
/// </summary>
/// <value>The reserved urls.</value>
public static string ReservedUrls
{
get
2013-02-27 23:02:12 +06:00
{
if ( _reservedUrls = = null )
{
var urls = ConfigurationManager . AppSettings . ContainsKey ( "umbracoReservedUrls" )
? ConfigurationManager . AppSettings [ "umbracoReservedUrls" ]
: string . Empty ;
2013-02-27 20:13:15 +06:00
2013-02-27 23:02:12 +06:00
//ensure the built on (non-changeable) reserved paths are there at all times
_reservedUrls = StaticReservedUrls + urls ;
}
return _reservedUrls ;
2012-07-28 00:13:06 +06:00
}
2013-02-27 23:02:12 +06:00
internal set { _reservedUrls = value ; }
2012-07-28 00:13:06 +06:00
}
/// <summary>
/// Gets the reserved paths from web.config
/// </summary>
/// <value>The reserved paths.</value>
public static string ReservedPaths
{
get
{
2013-02-27 23:02:12 +06:00
if ( _reservedPaths = = null )
2013-02-27 20:42:11 +06:00
{
2013-02-27 23:02:12 +06:00
var reservedPaths = StaticReservedPaths ;
//always add the umbraco path to the list
if ( ConfigurationManager . AppSettings . ContainsKey ( "umbracoPath" )
& & ! ConfigurationManager . AppSettings [ "umbracoPath" ] . IsNullOrWhiteSpace ( ) )
{
reservedPaths + = ConfigurationManager . AppSettings [ "umbracoPath" ] . EnsureEndsWith ( ',' ) ;
}
2013-02-27 20:13:15 +06:00
2013-02-27 23:02:12 +06:00
var allPaths = ConfigurationManager . AppSettings . ContainsKey ( "umbracoReservedPaths" )
? ConfigurationManager . AppSettings [ "umbracoReservedPaths" ]
: string . Empty ;
2013-02-27 20:13:15 +06:00
2013-02-27 23:02:12 +06:00
_reservedPaths = reservedPaths + allPaths ;
}
return _reservedPaths ;
2012-07-28 00:13:06 +06:00
}
2013-02-27 23:02:12 +06:00
internal set { _reservedPaths = value ; }
2012-07-28 00:13:06 +06:00
}
/// <summary>
/// Gets the name of the content XML file.
/// </summary>
/// <value>The content XML.</value>
2013-06-24 13:37:25 +10:00
/// <remarks>
/// Defaults to ~/App_Data/umbraco.config
/// </remarks>
2012-09-13 09:00:21 +07:00
public static string ContentXmlFile
2012-07-28 00:13:06 +06:00
{
get
2012-12-31 12:15:46 -01:00
{
return ConfigurationManager . AppSettings . ContainsKey ( "umbracoContentXML" )
? ConfigurationManager . AppSettings [ "umbracoContentXML" ]
2013-06-24 13:37:25 +10:00
: "~/App_Data/umbraco.config" ;
2012-07-28 00:13:06 +06:00
}
}
/// <summary>
/// Gets the path to the storage directory (/data by default).
/// </summary>
/// <value>The storage directory.</value>
public static string StorageDirectory
{
get
{
2012-12-31 12:15:46 -01:00
return ConfigurationManager . AppSettings . ContainsKey ( "umbracoStorageDirectory" )
? ConfigurationManager . AppSettings [ "umbracoStorageDirectory" ]
2013-06-24 13:37:25 +10:00
: "~/App_Data" ;
2012-07-28 00:13:06 +06:00
}
}
/// <summary>
/// Gets the path to umbraco's root directory (/umbraco by default).
/// </summary>
/// <value>The path.</value>
public static string Path
{
get
{
2012-12-31 12:15:46 -01:00
return ConfigurationManager . AppSettings . ContainsKey ( "umbracoPath" )
? IOHelper . ResolveUrl ( ConfigurationManager . AppSettings [ "umbracoPath" ] )
: string . Empty ;
}
}
/// <summary>
/// This returns the string of the MVC Area route.
/// </summary>
/// <remarks>
/// THIS IS TEMPORARY AND SHOULD BE REMOVED WHEN WE MIGRATE/UPDATE THE CONFIG SETTINGS TO BE A REAL CONFIG SECTION
/// AND SHOULD PROBABLY BE HANDLED IN A MORE ROBUST WAY.
///
/// This will return the MVC area that we will route all custom routes through like surface controllers, etc...
/// We will use the 'Path' (default ~/umbraco) to create it but since it cannot contain '/' and people may specify a path of ~/asdf/asdf/admin
/// we will convert the '/' to '-' and use that as the path. its a bit lame but will work.
2013-03-15 08:03:19 +04:00
///
/// We also make sure that the virtual directory (SystemDirectories.Root) is stripped off first, otherwise we'd end up with something
/// like "MyVirtualDirectory-Umbraco" instead of just "Umbraco".
2012-12-31 12:15:46 -01:00
/// </remarks>
2015-04-13 13:33:13 +10:00
public static string UmbracoMvcArea
2012-12-31 12:15:46 -01:00
{
get
{
if ( Path . IsNullOrWhiteSpace ( ) )
{
throw new InvalidOperationException ( "Cannot create an MVC Area path without the umbracoPath specified" ) ;
}
2013-11-01 09:51:54 +01:00
var path = Path ;
if ( path . StartsWith ( SystemDirectories . Root ) ) // beware of TrimStart, see U4-2518
path = path . Substring ( SystemDirectories . Root . Length ) ;
return path . TrimStart ( '~' ) . TrimStart ( '/' ) . Replace ( '/' , '-' ) . Trim ( ) . ToLower ( ) ;
2012-12-31 12:15:46 -01:00
}
}
2012-09-05 09:35:24 +07:00
2012-07-28 00:13:06 +06:00
/// <summary>
/// Gets the path to umbraco's client directory (/umbraco_client by default).
/// This is a relative path to the Umbraco Path as it always must exist beside the 'umbraco'
/// folder since the CSS paths to images depend on it.
/// </summary>
/// <value>The path.</value>
public static string ClientPath
{
get
{
return Path + "/../umbraco_client" ;
}
}
/// <summary>
/// Gets the database connection string
/// </summary>
/// <value>The database connection string.</value>
2013-08-23 14:17:40 +02:00
[Obsolete("Use System.Configuration.ConfigurationManager.ConnectionStrings[\"umbracoDbDSN\"] instead ")]
2012-07-28 00:13:06 +06:00
public static string DbDsn
{
get
{
2017-01-12 17:33:30 +11:00
var settings = ConfigurationManager . ConnectionStrings [ Constants . System . UmbracoConnectionName ] ;
2012-12-31 12:15:46 -01:00
var connectionString = string . Empty ;
if ( settings ! = null )
{
connectionString = settings . ConnectionString ;
2013-08-23 14:17:40 +02:00
// The SqlCe connectionString is formatted slightly differently, so we need to update it
2012-12-31 12:15:46 -01:00
if ( settings . ProviderName . Contains ( "SqlServerCe" ) )
connectionString = string . Format ( "datalayer=SQLCE4Umbraco.SqlCEHelper,SQLCE4Umbraco;{0}" , connectionString ) ;
}
return connectionString ;
2012-07-28 00:13:06 +06:00
}
set
{
if ( DbDsn ! = value )
{
2012-12-31 12:28:38 -01:00
if ( value . ToLower ( ) . Contains ( "SQLCE4Umbraco.SqlCEHelper" . ToLower ( ) ) )
{
2013-01-29 11:30:20 -01:00
ApplicationContext . Current . DatabaseContext . ConfigureEmbeddedDatabaseConnection ( ) ;
2012-12-31 12:28:38 -01:00
}
else
{
ApplicationContext . Current . DatabaseContext . ConfigureDatabaseConnection ( value ) ;
}
2012-07-28 00:13:06 +06:00
}
}
}
2017-01-12 17:33:30 +11:00
2012-10-29 09:49:31 -01:00
2012-07-28 00:13:06 +06:00
/// <summary>
/// Gets or sets the configuration status. This will return the version number of the currently installed umbraco instance.
/// </summary>
/// <value>The configuration status.</value>
public static string ConfigurationStatus
{
get
{
2012-12-31 12:15:46 -01:00
return ConfigurationManager . AppSettings . ContainsKey ( "umbracoConfigurationStatus" )
? ConfigurationManager . AppSettings [ "umbracoConfigurationStatus" ]
: string . Empty ;
2012-07-28 00:13:06 +06:00
}
set
{
SaveSetting ( "umbracoConfigurationStatus" , value ) ;
}
}
2014-02-22 16:44:02 +01:00
/// <summary>
/// Gets or sets the Umbraco members membership providers' useLegacyEncoding state. This will return a boolean
/// </summary>
/// <value>The useLegacyEncoding status.</value>
public static bool UmbracoMembershipProviderLegacyEncoding
{
get
{
2014-02-26 02:57:05 +11:00
return IsConfiguredMembershipProviderUsingLegacyEncoding ( Constants . Conventions . Member . UmbracoMemberProviderName ) ;
2014-02-22 16:44:02 +01:00
}
set
{
SetMembershipProvidersLegacyEncoding ( Constants . Conventions . Member . UmbracoMemberProviderName , value ) ;
}
}
/// <summary>
/// Gets or sets the Umbraco users membership providers' useLegacyEncoding state. This will return a boolean
/// </summary>
/// <value>The useLegacyEncoding status.</value>
public static bool UmbracoUsersMembershipProviderLegacyEncoding
{
get
{
2014-03-18 19:05:07 +11:00
return IsConfiguredMembershipProviderUsingLegacyEncoding ( UmbracoConfig . For . UmbracoSettings ( ) . Providers . DefaultBackOfficeUserProvider ) ;
2014-02-22 16:44:02 +01:00
}
set
{
2014-03-18 19:05:07 +11:00
SetMembershipProvidersLegacyEncoding ( UmbracoConfig . For . UmbracoSettings ( ) . Providers . DefaultBackOfficeUserProvider , value ) ;
2014-02-22 16:44:02 +01:00
}
}
2012-09-13 09:00:21 +07:00
2012-07-28 00:13:06 +06:00
/// <summary>
/// Saves a setting into the configuration file.
/// </summary>
/// <param name="key">Key of the setting to be saved.</param>
/// <param name="value">Value of the setting to be saved.</param>
internal static void SaveSetting ( string key , string value )
{
2013-12-06 12:16:36 +01:00
var fileName = IOHelper . MapPath ( string . Format ( "{0}/web.config" , SystemDirectories . Root ) ) ;
2012-12-11 16:23:15 -01:00
var xml = XDocument . Load ( fileName , LoadOptions . PreserveWhitespace ) ;
2012-12-31 12:15:46 -01:00
2013-10-04 10:34:00 +10:00
var appSettings = xml . Root . DescendantsAndSelf ( "appSettings" ) . Single ( ) ;
2012-10-06 18:46:12 -02:00
// Update appSetting if it exists, or else create a new appSetting for the given key and value
2012-12-31 12:15:46 -01:00
var setting = appSettings . Descendants ( "add" ) . FirstOrDefault ( s = > s . Attribute ( "key" ) . Value = = key ) ;
2012-10-06 18:46:12 -02:00
if ( setting = = null )
appSettings . Add ( new XElement ( "add" , new XAttribute ( "key" , key ) , new XAttribute ( "value" , value ) ) ) ;
else
setting . Attribute ( "value" ) . Value = value ;
2012-12-11 16:23:15 -01:00
xml . Save ( fileName , SaveOptions . DisableFormatting ) ;
2012-07-28 00:13:06 +06:00
ConfigurationManager . RefreshSection ( "appSettings" ) ;
}
2012-12-31 12:15:46 -01:00
/// <summary>
/// Removes a setting from the configuration file.
/// </summary>
/// <param name="key">Key of the setting to be removed.</param>
internal static void RemoveSetting ( string key )
{
2013-12-06 12:16:36 +01:00
var fileName = IOHelper . MapPath ( string . Format ( "{0}/web.config" , SystemDirectories . Root ) ) ;
2012-12-31 12:15:46 -01:00
var xml = XDocument . Load ( fileName , LoadOptions . PreserveWhitespace ) ;
2013-10-04 10:34:00 +10:00
var appSettings = xml . Root . DescendantsAndSelf ( "appSettings" ) . Single ( ) ;
2012-12-31 12:15:46 -01:00
var setting = appSettings . Descendants ( "add" ) . FirstOrDefault ( s = > s . Attribute ( "key" ) . Value = = key ) ;
2013-01-07 09:39:39 -01:00
2012-12-31 12:28:38 -01:00
if ( setting ! = null )
2013-01-07 09:39:39 -01:00
{
2012-12-31 12:15:46 -01:00
setting . Remove ( ) ;
2013-01-07 09:39:39 -01:00
xml . Save ( fileName , SaveOptions . DisableFormatting ) ;
ConfigurationManager . RefreshSection ( "appSettings" ) ;
2014-02-25 02:30:05 +11:00
}
2012-12-31 12:15:46 -01:00
}
2014-02-22 16:44:02 +01:00
private static void SetMembershipProvidersLegacyEncoding ( string providerName , bool useLegacyEncoding )
{
2014-02-26 02:57:05 +11:00
//check if this can even be configured.
var membershipProvider = Membership . Providers [ providerName ] as MembershipProviderBase ;
if ( membershipProvider = = null )
{
return ;
}
if ( membershipProvider . GetType ( ) . Namespace = = "umbraco.providers.members" )
{
//its the legacy one, this cannot be changed
return ;
}
2014-02-25 02:30:05 +11:00
var webConfigFilename = IOHelper . MapPath ( string . Format ( "{0}/web.config" , SystemDirectories . Root ) ) ;
2014-02-22 16:44:02 +01:00
var webConfigXml = XDocument . Load ( webConfigFilename , LoadOptions . PreserveWhitespace ) ;
var membershipConfigs = webConfigXml . XPathSelectElements ( "configuration/system.web/membership/providers/add" ) . ToList ( ) ;
if ( membershipConfigs . Any ( ) = = false )
return ;
var provider = membershipConfigs . SingleOrDefault ( c = > c . Attribute ( "name" ) ! = null & & c . Attribute ( "name" ) . Value = = providerName ) ;
if ( provider = = null )
return ;
provider . SetAttributeValue ( "useLegacyEncoding" , useLegacyEncoding ) ;
webConfigXml . Save ( webConfigFilename , SaveOptions . DisableFormatting ) ;
}
2014-02-25 02:30:05 +11:00
2014-02-26 02:57:05 +11:00
private static bool IsConfiguredMembershipProviderUsingLegacyEncoding ( string providerName )
2014-02-22 16:44:02 +01:00
{
2014-02-26 02:57:05 +11:00
//check if this can even be configured.
var membershipProvider = Membership . Providers [ providerName ] as MembershipProviderBase ;
if ( membershipProvider = = null )
{
return false ;
}
2014-02-25 02:30:05 +11:00
2014-02-26 02:57:05 +11:00
return membershipProvider . UseLegacyEncoding ;
2014-02-25 02:30:05 +11:00
}
2012-07-28 00:13:06 +06:00
/// <summary>
/// Gets the full path to root.
/// </summary>
/// <value>The fullpath to root.</value>
public static string FullpathToRoot
{
2012-12-29 18:18:49 -01:00
get { return IOHelper . GetRootDirectorySafe ( ) ; }
2012-07-28 00:13:06 +06:00
}
/// <summary>
/// Gets a value indicating whether umbraco is running in [debug mode].
/// </summary>
/// <value><c>true</c> if [debug mode]; otherwise, <c>false</c>.</value>
public static bool DebugMode
{
get
{
try
{
2013-06-21 16:20:18 +10:00
if ( HttpContext . Current ! = null )
{
return HttpContext . Current . IsDebuggingEnabled ;
}
//go and get it from config directly
var section = ConfigurationManager . GetSection ( "system.web/compilation" ) as CompilationSection ;
return section ! = null & & section . Debug ;
2012-07-28 00:13:06 +06:00
}
catch
{
return false ;
}
}
}
/// <summary>
/// Gets a value indicating whether the current version of umbraco is configured.
/// </summary>
/// <value><c>true</c> if configured; otherwise, <c>false</c>.</value>
2015-06-24 14:17:24 +02:00
[Obsolete("Do not use this, it is no longer in use and will be removed from the codebase in future versions")]
internal static bool Configured
2012-07-28 00:13:06 +06:00
{
get
{
try
{
string configStatus = ConfigurationStatus ;
2015-07-07 10:12:34 +02:00
string currentVersion = UmbracoVersion . GetSemanticVersion ( ) . ToSemanticString ( ) ;
2012-07-28 00:13:06 +06:00
if ( currentVersion ! = configStatus )
{
2012-12-31 12:15:46 -01:00
LogHelper . Debug < GlobalSettings > ( "CurrentVersion different from configStatus: '" + currentVersion + "','" + configStatus + "'" ) ;
2012-07-28 00:13:06 +06:00
}
2012-12-31 12:15:46 -01:00
2012-07-28 00:13:06 +06:00
return ( configStatus = = currentVersion ) ;
}
catch
{
return false ;
}
}
}
/// <summary>
/// Gets the time out in minutes.
/// </summary>
/// <value>The time out in minutes.</value>
public static int TimeOutInMinutes
{
get
{
try
{
return int . Parse ( ConfigurationManager . AppSettings [ "umbracoTimeOutInMinutes" ] ) ;
}
catch
{
return 20 ;
}
}
}
/// <summary>
/// Gets a value indicating whether umbraco uses directory urls.
/// </summary>
/// <value><c>true</c> if umbraco uses directory urls; otherwise, <c>false</c>.</value>
public static bool UseDirectoryUrls
{
get
{
try
{
return bool . Parse ( ConfigurationManager . AppSettings [ "umbracoUseDirectoryUrls" ] ) ;
}
catch
{
return false ;
}
}
}
/// <summary>
/// Returns a string value to determine if umbraco should skip version-checking.
/// </summary>
/// <value>The version check period in days (0 = never).</value>
public static int VersionCheckPeriod
{
get
{
2012-12-31 12:15:46 -01:00
try
{
return int . Parse ( ConfigurationManager . AppSettings [ "umbracoVersionCheckPeriod" ] ) ;
}
catch
{
return 7 ;
}
2012-07-28 00:13:06 +06:00
}
}
2012-12-31 12:15:46 -01:00
2012-07-28 00:13:06 +06:00
/// <summary>
/// Returns a string value to determine if umbraco should disbable xslt extensions
/// </summary>
/// <value><c>"true"</c> if version xslt extensions are disabled, otherwise, <c>"false"</c></value>
2013-06-24 13:37:25 +10:00
[Obsolete("This is no longer used and will be removed from the codebase in future releases")]
2012-07-28 00:13:06 +06:00
public static string DisableXsltExtensions
{
get
{
2012-12-31 12:15:46 -01:00
return ConfigurationManager . AppSettings . ContainsKey ( "umbracoDisableXsltExtensions" )
? ConfigurationManager . AppSettings [ "umbracoDisableXsltExtensions" ]
2013-06-24 13:37:25 +10:00
: "false" ;
}
}
internal static bool ContentCacheXmlStoredInCodeGen
2017-02-28 23:53:12 +01:00
{
2017-10-06 11:47:25 +11:00
get { return LocalTempStorageLocation = = LocalTempStorage . AspNetTemp ; }
2017-02-28 23:53:12 +01:00
}
2017-10-06 11:47:25 +11:00
/// <summary>
/// This is the location type to store temporary files such as cache files or other localized files for a given machine
/// </summary>
/// <remarks>
/// Currently used for the xml cache file and the plugin cache files
/// </remarks>
internal static LocalTempStorage LocalTempStorageLocation
2013-06-24 13:37:25 +10:00
{
get
2017-10-06 11:47:25 +11:00
{
//there's a bunch of backwards compat config checks here....
//This is the current one
if ( ConfigurationManager . AppSettings . ContainsKey ( "umbracoLocalTempStorage" ) )
{
return Enum < LocalTempStorage > . Parse ( ConfigurationManager . AppSettings [ "umbracoLocalTempStorage" ] ) ;
}
//This one is old
2017-02-28 23:53:12 +01:00
if ( ConfigurationManager . AppSettings . ContainsKey ( "umbracoContentXMLStorage" ) )
{
2017-10-06 11:47:25 +11:00
return Enum < LocalTempStorage > . Parse ( ConfigurationManager . AppSettings [ "umbracoContentXMLStorage" ] ) ;
}
//This one is older
2017-02-28 23:53:12 +01:00
if ( ConfigurationManager . AppSettings . ContainsKey ( "umbracoContentXMLUseLocalTemp" ) )
{
return bool . Parse ( ConfigurationManager . AppSettings [ "umbracoContentXMLUseLocalTemp" ] )
2017-10-06 11:47:25 +11:00
? LocalTempStorage . AspNetTemp
: LocalTempStorage . Default ;
2017-02-28 23:53:12 +01:00
}
2017-10-06 11:47:25 +11:00
return LocalTempStorage . Default ;
2012-07-28 00:13:06 +06:00
}
}
/// <summary>
/// Returns a string value to determine if umbraco should use Xhtml editing mode in the wysiwyg editor
/// </summary>
/// <value><c>"true"</c> if Xhtml mode is enable, otherwise, <c>"false"</c></value>
2013-06-24 13:37:25 +10:00
[Obsolete("This is no longer used and will be removed from the codebase in future releases")]
2012-07-28 00:13:06 +06:00
public static string EditXhtmlMode
{
2013-06-24 13:37:25 +10:00
get { return "true" ; }
2012-07-28 00:13:06 +06:00
}
/// <summary>
/// Gets the default UI language.
/// </summary>
/// <value>The default UI language.</value>
public static string DefaultUILanguage
{
get
{
2012-12-31 12:15:46 -01:00
return ConfigurationManager . AppSettings . ContainsKey ( "umbracoDefaultUILanguage" )
? ConfigurationManager . AppSettings [ "umbracoDefaultUILanguage" ]
: string . Empty ;
2012-07-28 00:13:06 +06:00
}
}
/// <summary>
/// Gets the profile URL.
/// </summary>
/// <value>The profile URL.</value>
public static string ProfileUrl
{
get
{
2013-06-24 13:37:25 +10:00
//the default will be 'profiler'
2012-12-31 12:15:46 -01:00
return ConfigurationManager . AppSettings . ContainsKey ( "umbracoProfileUrl" )
? ConfigurationManager . AppSettings [ "umbracoProfileUrl" ]
2013-06-24 13:37:25 +10:00
: "profiler" ;
2012-07-28 00:13:06 +06:00
}
}
/// <summary>
/// Gets a value indicating whether umbraco should hide top level nodes from generated urls.
/// </summary>
/// <value>
/// <c>true</c> if umbraco hides top level nodes from urls; otherwise, <c>false</c>.
/// </value>
public static bool HideTopLevelNodeFromPath
{
get
{
2012-12-31 12:15:46 -01:00
try
{
return bool . Parse ( ConfigurationManager . AppSettings [ "umbracoHideTopLevelNodeFromPath" ] ) ;
}
catch
{
return false ;
}
2012-07-28 00:13:06 +06:00
}
}
/// <summary>
/// Gets the current version.
/// </summary>
/// <value>The current version.</value>
2012-11-26 11:18:06 -01:00
[Obsolete("Use Umbraco.Core.Configuration.UmbracoVersion.Current instead", false)]
2012-07-28 00:13:06 +06:00
public static string CurrentVersion
{
2015-07-07 10:12:34 +02:00
get { return UmbracoVersion . GetSemanticVersion ( ) . ToSemanticString ( ) ; }
2012-07-28 00:13:06 +06:00
}
/// <summary>
/// Gets the major version number.
/// </summary>
/// <value>The major version number.</value>
2012-11-26 11:18:06 -01:00
[Obsolete("Use Umbraco.Core.Configuration.UmbracoVersion.Current instead", false)]
2012-07-28 00:13:06 +06:00
public static int VersionMajor
{
get
{
2012-11-26 11:18:06 -01:00
return UmbracoVersion . Current . Major ;
2012-07-28 00:13:06 +06:00
}
}
/// <summary>
/// Gets the minor version number.
/// </summary>
/// <value>The minor version number.</value>
2012-11-26 11:18:06 -01:00
[Obsolete("Use Umbraco.Core.Configuration.UmbracoVersion.Current instead", false)]
2012-07-28 00:13:06 +06:00
public static int VersionMinor
{
get
{
2012-11-26 11:18:06 -01:00
return UmbracoVersion . Current . Minor ;
2012-07-28 00:13:06 +06:00
}
}
/// <summary>
/// Gets the patch version number.
/// </summary>
/// <value>The patch version number.</value>
2012-11-26 11:18:06 -01:00
[Obsolete("Use Umbraco.Core.Configuration.UmbracoVersion.Current instead", false)]
2012-07-28 00:13:06 +06:00
public static int VersionPatch
{
get
{
2012-11-26 11:18:06 -01:00
return UmbracoVersion . Current . Build ;
2012-07-28 00:13:06 +06:00
}
}
/// <summary>
/// Gets the version comment (like beta or RC).
/// </summary>
/// <value>The version comment.</value>
2012-11-26 11:18:06 -01:00
[Obsolete("Use Umbraco.Core.Configuration.UmbracoVersion.Current instead", false)]
2012-07-28 00:13:06 +06:00
public static string VersionComment
{
get
{
2012-11-26 11:18:06 -01:00
return Umbraco . Core . Configuration . UmbracoVersion . CurrentComment ;
2012-07-28 00:13:06 +06:00
}
}
/// <summary>
/// Requests the is in umbraco application directory structure.
/// </summary>
/// <param name="context">The context.</param>
/// <returns></returns>
public static bool RequestIsInUmbracoApplication ( HttpContext context )
{
return context . Request . Path . ToLower ( ) . IndexOf ( IOHelper . ResolveUrl ( SystemDirectories . Umbraco ) . ToLower ( ) ) > - 1 ;
}
2013-02-09 04:05:01 +06:00
public static bool RequestIsInUmbracoApplication ( HttpContextBase context )
{
return context . Request . Path . ToLower ( ) . IndexOf ( IOHelper . ResolveUrl ( SystemDirectories . Umbraco ) . ToLower ( ) ) > - 1 ;
}
2012-07-28 00:13:06 +06:00
/// <summary>
/// Gets a value indicating whether umbraco should force a secure (https) connection to the backoffice.
/// </summary>
/// <value><c>true</c> if [use SSL]; otherwise, <c>false</c>.</value>
public static bool UseSSL
{
get
{
try
{
return bool . Parse ( ConfigurationManager . AppSettings [ "umbracoUseSSL" ] ) ;
}
catch
{
return false ;
}
}
}
/// <summary>
/// Gets the umbraco license.
/// </summary>
/// <value>The license.</value>
public static string License
{
get
{
string license =
"<A href=\"http://umbraco.org/redir/license\" target=\"_blank\">the open source license MIT</A>. The umbraco UI is freeware licensed under the umbraco license." ;
2012-12-31 12:15:46 -01:00
var versionDoc = new XmlDocument ( ) ;
var versionReader = new XmlTextReader ( IOHelper . MapPath ( SystemDirectories . Umbraco + "/version.xml" ) ) ;
versionDoc . Load ( versionReader ) ;
versionReader . Close ( ) ;
// check for license
try
{
string licenseUrl =
versionDoc . SelectSingleNode ( "/version/licensing/licenseUrl" ) . FirstChild . Value ;
string licenseValidation =
versionDoc . SelectSingleNode ( "/version/licensing/licenseValidation" ) . FirstChild . Value ;
string licensedTo =
versionDoc . SelectSingleNode ( "/version/licensing/licensedTo" ) . FirstChild . Value ;
if ( licensedTo ! = "" & & licenseUrl ! = "" )
{
license = "umbraco Commercial License<br/><b>Registered to:</b><br/>" +
licensedTo . Replace ( "\n" , "<br/>" ) + "<br/><b>For use with domain:</b><br/>" +
licenseUrl ;
}
}
catch
{
}
2012-09-13 09:00:21 +07:00
return license ;
2012-07-28 00:13:06 +06:00
}
}
2012-12-31 12:15:46 -01:00
/// <summary>
/// Determines whether the current request is reserved based on the route table and
/// whether the specified URL is reserved or is inside a reserved path.
/// </summary>
/// <param name="url"></param>
/// <param name="httpContext"></param>
/// <param name="routes">The route collection to lookup the request in</param>
/// <returns></returns>
public static bool IsReservedPathOrUrl ( string url , HttpContextBase httpContext , RouteCollection routes )
{
if ( httpContext = = null ) throw new ArgumentNullException ( "httpContext" ) ;
if ( routes = = null ) throw new ArgumentNullException ( "routes" ) ;
2012-11-19 19:56:52 +05:00
2012-12-31 12:15:46 -01:00
//check if the current request matches a route, if so then it is reserved.
var route = routes . GetRouteData ( httpContext ) ;
if ( route ! = null )
return true ;
2012-11-19 19:56:52 +05:00
2012-12-31 12:15:46 -01:00
//continue with the standard ignore routine
return IsReservedPathOrUrl ( url ) ;
}
2012-11-19 19:56:52 +05:00
2012-12-31 12:15:46 -01:00
/// <summary>
2012-07-28 00:13:06 +06:00
/// Determines whether the specified URL is reserved or is inside a reserved path.
/// </summary>
/// <param name="url">The URL to check.</param>
/// <returns>
/// <c>true</c> if the specified URL is reserved; otherwise, <c>false</c>.
/// </returns>
public static bool IsReservedPathOrUrl ( string url )
2012-12-31 12:15:46 -01:00
{
2013-02-27 20:42:11 +06:00
if ( _reservedUrlsCache = = null )
2012-07-28 00:13:06 +06:00
{
2013-02-27 20:42:11 +06:00
lock ( Locker )
2012-07-28 00:13:06 +06:00
{
2013-02-27 20:42:11 +06:00
if ( _reservedUrlsCache = = null )
{
// store references to strings to determine changes
_reservedPathsCache = GlobalSettings . ReservedPaths ;
_reservedUrlsCache = GlobalSettings . ReservedUrls ;
2015-10-20 09:48:58 +02:00
2013-02-27 20:42:11 +06:00
// add URLs and paths to a new list
2015-10-20 09:48:58 +02:00
var newReservedList = new HashSet < string > ( ) ;
foreach ( var reservedUrlTrimmed in _reservedUrlsCache
. Split ( new [ ] { "," } , StringSplitOptions . RemoveEmptyEntries )
. Select ( x = > x . Trim ( ) . ToLowerInvariant ( ) )
. Where ( x = > x . IsNullOrWhiteSpace ( ) = = false )
. Select ( reservedUrl = > IOHelper . ResolveUrl ( reservedUrl ) . Trim ( ) . EnsureStartsWith ( "/" ) )
. Where ( reservedUrlTrimmed = > reservedUrlTrimmed . IsNullOrWhiteSpace ( ) = = false ) )
2013-02-27 20:42:11 +06:00
{
2015-10-20 09:48:58 +02:00
newReservedList . Add ( reservedUrlTrimmed ) ;
2013-02-27 20:42:11 +06:00
}
2015-10-20 09:48:58 +02:00
foreach ( var reservedPathTrimmed in _reservedPathsCache
. Split ( new [ ] { "," } , StringSplitOptions . RemoveEmptyEntries )
. Select ( x = > x . Trim ( ) . ToLowerInvariant ( ) )
. Where ( x = > x . IsNullOrWhiteSpace ( ) = = false )
. Select ( reservedPath = > IOHelper . ResolveUrl ( reservedPath ) . Trim ( ) . EnsureStartsWith ( "/" ) . EnsureEndsWith ( "/" ) )
. Where ( reservedPathTrimmed = > reservedPathTrimmed . IsNullOrWhiteSpace ( ) = = false ) )
2013-02-27 20:42:11 +06:00
{
2015-10-20 09:48:58 +02:00
newReservedList . Add ( reservedPathTrimmed ) ;
2013-02-27 20:42:11 +06:00
}
// use the new list from now on
2015-10-20 09:48:58 +02:00
_reservedList = newReservedList ;
2013-02-27 20:42:11 +06:00
}
2012-07-28 00:13:06 +06:00
}
}
2012-12-31 12:15:46 -01:00
//The url should be cleaned up before checking:
// * If it doesn't contain an '.' in the path then we assume it is a path based URL, if that is the case we should add an trailing '/' because all of our reservedPaths use a trailing '/'
// * We shouldn't be comparing the query at all
2015-10-20 09:48:58 +02:00
var pathPart = url . Split ( new [ ] { '?' } , StringSplitOptions . RemoveEmptyEntries ) [ 0 ] . ToLowerInvariant ( ) ;
if ( pathPart . Contains ( "." ) = = false )
2012-12-31 12:15:46 -01:00
{
2015-10-20 09:48:58 +02:00
pathPart = pathPart . EnsureEndsWith ( '/' ) ;
2012-12-31 12:15:46 -01:00
}
2012-07-28 00:13:06 +06:00
// return true if url starts with an element of the reserved list
2015-10-20 09:48:58 +02:00
return _reservedList . Any ( x = > pathPart . InvariantStartsWith ( x ) ) ;
2012-12-31 12:15:46 -01:00
}
2015-10-20 09:48:58 +02:00
2012-07-28 00:13:06 +06:00
}
2012-12-31 12:15:46 -01:00
2012-07-28 00:13:06 +06:00
}