//****************************************************************************************************** // WebServerOptions.cs - Gbtc // // Copyright © 2017, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may // not use this file except in compliance with the License. You may obtain a copy of the License at: // // http://opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 08/27/2017 - J. Ritchie Carroll // Generated original version of source code. // //****************************************************************************************************** using GSF.Web.Security; namespace GSF.Web.Hosting { /// /// Represents configuration options for a instance. /// public class WebServerOptions { #region [ Members ] // Constants /// /// Default value for . /// public const string DefaultWebRootPath = "wwwroot"; /// /// Default value for . /// public const bool DefaultClientCacheEnabled = true; /// /// Default value for . /// public const bool DefaultMinifyJavascript = true; /// /// Default value for . /// public const bool DefaultMinifyStyleSheets = true; /// /// Default value for . /// public const bool DefaultUseMinifyInDebug = false; // Fields private string m_authTestPage; #endregion #region [ Properties ] /// /// Gets or sets root path defined for this . /// public string WebRootPath { get; set; } = DefaultWebRootPath; /// /// Gets or sets flag that determines if cache control is enabled for browser clients; default to true. /// public bool ClientCacheEnabled { get; set; } = DefaultClientCacheEnabled; /// /// Gets or sets value that determines if minification should be applied to rendered Javascript files. /// public bool MinifyJavascript { get; set; } = DefaultMinifyJavascript; /// /// Gets or sets value that determines if minification should be applied to rendered CSS files. /// public bool MinifyStyleSheets { get; set; } = DefaultMinifyStyleSheets; /// /// Gets or sets value that determines if minification should be applied when running a Debug build. /// public bool UseMinifyInDebug { get; set; } = DefaultUseMinifyInDebug; /// /// Gets or sets the token used for identifying the session ID in cookie headers. /// public string SessionToken { get; set; } = SessionHandler.DefaultSessionToken; /// /// Gets or sets the page name used to test user authorization. /// /// /// Page name for web server use will not be prefixed with slash. Any slash /// prefix will automatically be removed during value assignment. /// public string AuthTestPage { get { if ((object)m_authTestPage == null) AuthTestPage = AuthenticationOptions.DefaultAuthTestPage; return m_authTestPage; } set { m_authTestPage = value; // Remove any slash prefix for WebServer use if (!string.IsNullOrEmpty(m_authTestPage) && m_authTestPage.StartsWith("/")) m_authTestPage = m_authTestPage.Length > 1 ? m_authTestPage.Substring(1) : ""; } } /// /// Gets an immutable version of the web server options. /// public ReadonlyWebServerOptions Readonly => new ReadonlyWebServerOptions(this); #endregion } /// /// Represents an immutable version of . /// public class ReadonlyWebServerOptions { #region [ Members ] // Fields private readonly WebServerOptions m_webServerOptions; #endregion #region [ Constructors ] internal ReadonlyWebServerOptions(WebServerOptions webServerOptions) { m_webServerOptions = webServerOptions; } #endregion #region [ Properties ] /// /// Gets root path defined for this . /// public string WebRootPath => m_webServerOptions.WebRootPath; /// /// Gets flag that determines if cache control is enabled for browser clients; default to true. /// public bool ClientCacheEnabled => m_webServerOptions.ClientCacheEnabled; /// /// Gets value that determines if minification should be applied to rendered Javascript files. /// public bool MinifyJavascript => m_webServerOptions.MinifyJavascript; /// /// Gets value that determines if minification should be applied to rendered CSS files. /// public bool MinifyStyleSheets => m_webServerOptions.MinifyStyleSheets; /// /// Gets value that determines if minification should be applied when running a Debug build. /// public bool UseMinifyInDebug => m_webServerOptions.UseMinifyInDebug; /// /// Gets the token used for identifying the session ID in cookie headers. /// public string SessionToken => m_webServerOptions.SessionToken; /// /// Gets the page name used to test user authorization. /// /// /// Page name for web server use will not be prefixed with slash. /// public string AuthTestPage => m_webServerOptions.AuthTestPage; #endregion } }