public override void Configure(Container container) { Plugins.Add(new ServerEventsFeature() { HeartbeatInterval = new TimeSpan(0, 1, 0) }); container.Register<ICacheClient>(new MemoryCacheClient()); ServiceStack.Text.JsConfig.EmitCamelCaseNames = true; ServiceStack.Text.JsConfig.DateHandler = ServiceStack.Text.DateHandler.ISO8601; HostConfig hostConfig = new HostConfig() { ReturnsInnerException = true }; SetConfig(hostConfig); }
public override void Configure(Container container) { Plugins.Add(new SwaggerFeature()); { var reqlog = new RequestLogsFeature(); Plugins.Add(reqlog); } { var cfgfile = new IniFile("stksto.ini", null); var dbhost = cfgfile.ReadValue("db", "host"); var dbport = int.Parse(cfgfile.ReadValue("db", "port")); var dbuser = cfgfile.ReadValue("db", "user"); var dbpwd = cfgfile.ReadValue("db", "pwd"); var dbname = cfgfile.ReadValue("db", "db"); OrmLiteConfig.DialectProvider = MySqlDialect.Provider; //先手工写,以后放到配置文件里去 var blder = new MySqlConnectionStringBuilder { Server = dbhost, Port = (uint)dbport, UserID = dbuser, Password = dbpwd, Database = dbname, OldGuids = true, CharacterSet = "utf8", Pooling = true }; string ConnStr = blder.GetConnectionString(true); container.Register<IDbConnectionFactory>(c => { return new OrmLiteConnectionFactory(ConnStr, MySqlDialect.Provider); }); } HostConfig conf = new HostConfig(); //conf.EnableFeatures = Feature.All.Remove(Feature.Csv | Feature.Soap | Feature.Jsv | Feature.Markdown); conf.DebugMode = true; SetConfig(conf); }
public static HostConfig NewInstance() { var config = new HostConfig { WsdlServiceNamespace = DefaultWsdlNamespace, ApiVersion = "1.0", EmbeddedResourceSources = new List<Assembly>(), EmbeddedResourceBaseTypes = new[] { HostContext.AppHost.GetType(), typeof(Service) }.ToList(), LogFactory = new NullLogFactory(), EnableAccessRestrictions = true, WebHostPhysicalPath = "~".MapServerPath(), HandlerFactoryPath = ServiceStackPath, MetadataRedirectPath = null, DefaultContentType = null, PreferredContentTypes = new List<string> { MimeTypes.Html, MimeTypes.Json, MimeTypes.Xml, MimeTypes.Jsv }, AllowJsonpRequests = true, AllowRouteContentTypeExtensions = true, AllowNonHttpOnlyCookies = false, UseHttpsLinks = false, DebugMode = false, DefaultDocuments = new List<string> { "default.htm", "default.html", "default.cshtml", "default.md", "index.htm", "index.html", "default.aspx", "default.ashx", }, GlobalResponseHeaders = new Dictionary<string, string> { { "Vary", "Accept" }, { "X-Powered-By", Env.ServerUserAgent }, }, IgnoreFormatsInMetadata = new HashSet<string>(StringComparer.OrdinalIgnoreCase), AllowFileExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "js", "css", "htm", "html", "shtm", "txt", "xml", "rss", "csv", "pdf", "jpg", "jpeg", "gif", "png", "bmp", "ico", "tif", "tiff", "svg", "avi", "divx", "m3u", "mov", "mp3", "mpeg", "mpg", "qt", "vob", "wav", "wma", "wmv", "flv", "swf", "xap", "xaml", "ogg", "mp4", "webm", "eot", "ttf", "woff", "map" }, DebugAspNetHostEnvironment = Env.IsMono ? "FastCGI" : "IIS7", DebugHttpListenerHostEnvironment = Env.IsMono ? "XSP" : "WebServer20", EnableFeatures = Feature.All, WriteErrorsToResponse = true, ReturnsInnerException = true, MarkdownOptions = new MarkdownOptions(), MarkdownBaseType = typeof(MarkdownViewBase), MarkdownGlobalHelpers = new Dictionary<string, Type>(), HtmlReplaceTokens = new Dictionary<string, string>(), AddMaxAgeForStaticMimeTypes = new Dictionary<string, TimeSpan> { { "image/gif", TimeSpan.FromHours(1) }, { "image/png", TimeSpan.FromHours(1) }, { "image/jpeg", TimeSpan.FromHours(1) }, }, AppendUtf8CharsetOnContentTypes = new HashSet<string> { MimeTypes.Json, }, RouteNamingConventions = new List<RouteNamingConventionDelegate> { RouteNamingConvention.WithRequestDtoName, RouteNamingConvention.WithMatchingAttributes, RouteNamingConvention.WithMatchingPropertyNames }, MapExceptionToStatusCode = new Dictionary<Type, int>(), OnlySendSessionCookiesSecurely = false, RestrictAllCookiesToDomain = null, DefaultJsonpCacheExpiration = new TimeSpan(0, 20, 0), MetadataVisibility = RequestAttributes.Any, Return204NoContentForEmptyResponse = true, AllowPartialResponses = true, AllowAclUrlReservation = true, RedirectToDefaultDocuments = false, StripApplicationVirtualPath = false, ScanSkipPaths = new List<string> { "/obj/", "/bin/", }, IgnoreWarningsOnPropertyNames = new List<string> { "format", "callback", "debug", "_", "authsecret" } }; if (config.HandlerFactoryPath == null) { config.InferHttpHandlerPath(); } return config; }
public static HostConfig ResetInstance() { return instance = NewInstance(); }
public static HostConfig NewInstance() { var config = new HostConfig { WsdlServiceNamespace = DefaultWsdlNamespace, ApiVersion = "1.0", EmbeddedResourceSources = new List<Assembly>(), EmbeddedResourceBaseTypes = new[] { HostContext.AppHost.GetType(), typeof(Service) }.ToList(), EmbeddedResourceTreatAsFiles = new HashSet<string>(), LogFactory = new NullLogFactory(), EnableAccessRestrictions = true, WebHostPhysicalPath = "~".MapServerPath(), HandlerFactoryPath = ServiceStackPath, MetadataRedirectPath = null, DefaultContentType = null, PreferredContentTypes = new List<string> { MimeTypes.Html, MimeTypes.Json, MimeTypes.Xml, MimeTypes.Jsv }, AllowJsonpRequests = true, AllowRouteContentTypeExtensions = true, AllowNonHttpOnlyCookies = false, DebugMode = false, DefaultDocuments = new List<string> { "default.htm", "default.html", "default.cshtml", "default.md", "index.htm", "index.html", "default.aspx", "default.ashx", }, GlobalResponseHeaders = new Dictionary<string, string> { { "Vary", "Accept" }, { "X-Powered-By", Env.ServerUserAgent }, }, IgnoreFormatsInMetadata = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { }, AllowFileExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "js", "ts", "tsx", "jsx", "css", "htm", "html", "shtm", "txt", "xml", "rss", "csv", "pdf", "jpg", "jpeg", "gif", "png", "bmp", "ico", "tif", "tiff", "svg", "avi", "divx", "m3u", "mov", "mp3", "mpeg", "mpg", "qt", "vob", "wav", "wma", "wmv", "flv", "swf", "xap", "xaml", "ogg", "ogv", "mp4", "webm", "eot", "ttf", "woff", "woff2", "map" }, AllowFilePaths = new List<string> { "jspm_packages/**/*.json" }, DebugAspNetHostEnvironment = Env.IsMono ? "FastCGI" : "IIS7", DebugHttpListenerHostEnvironment = Env.IsMono ? "XSP" : "WebServer20", EnableFeatures = Feature.All, WriteErrorsToResponse = true, ReturnsInnerException = true, DisposeDependenciesAfterUse = true, LogUnobservedTaskExceptions = true, MarkdownOptions = new MarkdownOptions(), MarkdownBaseType = typeof(MarkdownViewBase), MarkdownGlobalHelpers = new Dictionary<string, Type>(), HtmlReplaceTokens = new Dictionary<string, string>(), AddMaxAgeForStaticMimeTypes = new Dictionary<string, TimeSpan> { { "image/gif", TimeSpan.FromHours(1) }, { "image/png", TimeSpan.FromHours(1) }, { "image/jpeg", TimeSpan.FromHours(1) }, }, AppendUtf8CharsetOnContentTypes = new HashSet<string> { MimeTypes.Json, }, RouteNamingConventions = new List<RouteNamingConventionDelegate> { RouteNamingConvention.WithRequestDtoName, RouteNamingConvention.WithMatchingAttributes, RouteNamingConvention.WithMatchingPropertyNames }, MapExceptionToStatusCode = new Dictionary<Type, int>(), OnlySendSessionCookiesSecurely = false, AllowSessionIdsInHttpParams = false, AllowSessionCookies = true, RestrictAllCookiesToDomain = null, DefaultJsonpCacheExpiration = new TimeSpan(0, 20, 0), MetadataVisibility = RequestAttributes.Any, Return204NoContentForEmptyResponse = true, AllowJsConfig = true, AllowPartialResponses = true, AllowAclUrlReservation = true, AddRedirectParamsToQueryString = false, RedirectToDefaultDocuments = false, StripApplicationVirtualPath = false, ScanSkipPaths = new List<string> { "obj/", "bin/", "node_modules/", "jspm_packages/", "bower_components/", "wwwroot_build/", #if !NETSTANDARD1_6 "wwwroot/", //Need to allow VirtualFiles access from ContentRoot Folder #endif }, IgnoreWarningsOnPropertyNames = new List<string> { Keywords.Format, Keywords.Callback, Keywords.Debug, Keywords.AuthSecret, Keywords.IgnorePlaceHolder, Keywords.Version, Keywords.VersionAbbr, Keywords.Version.ToPascalCase(), }, XmlWriterSettings = new XmlWriterSettings { Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false), }, FallbackRestPath = null, UseHttpsLinks = false, #if !NETSTANDARD1_6 UseCamelCase = false, EnableOptimizations = false, #else UseCamelCase = true, EnableOptimizations = true, #endif DisableChunkedEncoding = false }; Platform.Instance.InitHostConifg(config); return config; }
public static HostConfig NewInstance() { var config = new HostConfig { MetadataTypesConfig = new MetadataTypesConfig(addDefaultXmlNamespace: "http://schemas.servicestack.net/types"), WsdlServiceNamespace = "http://schemas.servicestack.net/types", MetadataPageBodyHtml = @"<br /> <h3><a href=""https://github.com/ServiceStack/ServiceStack/wiki/Clients-overview"">Clients Overview</a></h3>", MetadataOperationPageBodyHtml = @"<br /> <h3><a href=""https://github.com/ServiceStack/ServiceStack/wiki/Clients-overview"">Clients Overview</a></h3>", MetadataCustomPath = "Views/Templates/Metadata/", UseCustomMetadataTemplates = false, LogFactory = new NullLogFactory(), EnableAccessRestrictions = true, WebHostPhysicalPath = "~".MapServerPath(), ServiceStackHandlerFactoryPath = ServiceStackPath, MetadataRedirectPath = null, DefaultContentType = null, AllowJsonpRequests = true, AllowRouteContentTypeExtensions = true, AllowNonHttpOnlyCookies = false, UseHttpsLinks = false, DebugMode = false, DefaultDocuments = new List<string> { "default.htm", "default.html", "default.cshtml", "default.md", "index.htm", "index.html", "default.aspx", "default.ashx", }, GlobalResponseHeaders = new Dictionary<string, string> { { "X-Powered-By", Env.ServerUserAgent } }, IgnoreFormatsInMetadata = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase), AllowFileExtensions = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase) { "js", "css", "htm", "html", "shtm", "txt", "xml", "rss", "csv", "pdf", "jpg", "jpeg", "gif", "png", "bmp", "ico", "tif", "tiff", "svg", "avi", "divx", "m3u", "mov", "mp3", "mpeg", "mpg", "qt", "vob", "wav", "wma", "wmv", "flv", "xap", "xaml", "ogg", "mp4", "webm", "eot", "ttf", "woff" }, DebugAspNetHostEnvironment = Env.IsMono ? "FastCGI" : "IIS7", DebugHttpListenerHostEnvironment = Env.IsMono ? "XSP" : "WebServer20", EnableFeatures = Feature.All, WriteErrorsToResponse = true, ReturnsInnerException = true, MarkdownOptions = new MarkdownOptions(), MarkdownBaseType = typeof(MarkdownViewBase), MarkdownGlobalHelpers = new Dictionary<string, Type>(), HtmlReplaceTokens = new Dictionary<string, string>(), AddMaxAgeForStaticMimeTypes = new Dictionary<string, TimeSpan> { { "image/gif", TimeSpan.FromHours(1) }, { "image/png", TimeSpan.FromHours(1) }, { "image/jpeg", TimeSpan.FromHours(1) }, }, AppendUtf8CharsetOnContentTypes = new HashSet<string> { MimeTypes.Json, }, RawHttpHandlers = new List<Func<IHttpRequest, IHttpHandler>>(), RouteNamingConventions = new List<RouteNamingConventionDelegate> { RouteNamingConvention.WithRequestDtoName, RouteNamingConvention.WithMatchingAttributes, RouteNamingConvention.WithMatchingPropertyNames }, CustomHttpHandlers = new Dictionary<HttpStatusCode, IServiceStackHttpHandler>(), GlobalHtmlErrorHttpHandler = null, MapExceptionToStatusCode = new Dictionary<Type, int>(), OnlySendSessionCookiesSecurely = false, RestrictAllCookiesToDomain = null, DefaultJsonpCacheExpiration = new TimeSpan(0, 20, 0), MetadataVisibility = RequestAttributes.Any, Return204NoContentForEmptyResponse = true, AllowPartialResponses = true, AllowAclUrlReservation = true, IgnoreWarningsOnPropertyNames = new List<string> { "format", "callback", "debug", "_", "authsecret" } }; if (config.ServiceStackHandlerFactoryPath == null) { config.InferHttpHandlerPath(); } return config; }
/// <summary> /// Set the host config of the AppHost. /// </summary> public virtual void SetConfig(HostConfig config) { Config = config; }
public static HostConfig ResetInstance() { return(instance = NewInstance()); }
public static HostConfig NewInstance() { var config = new HostConfig { WsdlServiceNamespace = DefaultWsdlNamespace, ApiVersion = "1.0", EmbeddedResourceSources = new List <Assembly>(), EmbeddedResourceBaseTypes = new[] { HostContext.AppHost.GetType(), typeof(Service) }.ToList(), EmbeddedResourceTreatAsFiles = new HashSet <string>(), EnableAccessRestrictions = true, EnableAutoHtmlResponses = true, WebHostPhysicalPath = "~".MapServerPath(), HandlerFactoryPath = ServiceStackPath, MetadataRedirectPath = null, DefaultContentType = null, PreferredContentTypes = new List <string> { MimeTypes.Html, MimeTypes.Json, MimeTypes.Xml, MimeTypes.Jsv }, AllowJsonpRequests = true, AllowRouteContentTypeExtensions = true, BufferSyncSerializers = Env.IsNetCore3, AllowNonHttpOnlyCookies = false, DebugMode = false, StrictMode = Env.StrictMode, DefaultDocuments = new List <string> { "default.htm", "default.html", "default.cshtml", "default.md", "index.htm", "index.html", "default.aspx", "default.ashx", }, GlobalResponseHeaders = new Dictionary <string, string> { { HttpHeaders.Vary, "Accept" }, { HttpHeaders.XPoweredBy, Env.ServerUserAgent }, }, IsMobileRegex = new Regex("Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune", RegexOptions.Compiled), RequestRules = new Dictionary <string, Func <IHttpRequest, bool> > { { "AcceptsHtml", req => req.Accept?.IndexOf(MimeTypes.Html, StringComparison.Ordinal) >= 0 }, { "AcceptsJson", req => req.Accept?.IndexOf(MimeTypes.Json, StringComparison.Ordinal) >= 0 }, { "AcceptsXml", req => req.Accept?.IndexOf(MimeTypes.Xml, StringComparison.Ordinal) >= 0 }, { "AcceptsJsv", req => req.Accept?.IndexOf(MimeTypes.Jsv, StringComparison.Ordinal) >= 0 }, { "AcceptsCsv", req => req.Accept?.IndexOf(MimeTypes.Csv, StringComparison.Ordinal) >= 0 }, { "IsAuthenticated", req => req.IsAuthenticated() }, { "IsMobile", req => Instance.IsMobileRegex.IsMatch(req.UserAgent) }, { "{int}/**", req => int.TryParse(req.PathInfo.Substring(1).LeftPart('/'), out _) }, { "path/{int}/**", req => { var afterFirst = req.PathInfo.Substring(1).RightPart('/'); return(!string.IsNullOrEmpty(afterFirst) && int.TryParse(afterFirst.LeftPart('/'), out _)); } }, { "**/{int}", req => int.TryParse(req.PathInfo.LastRightPart('/'), out _) }, { "**/{int}/path", req => { var beforeLast = req.PathInfo.LastLeftPart('/'); return(!string.IsNullOrEmpty(beforeLast) && int.TryParse(beforeLast.LastRightPart('/'), out _)); } }, }, IgnoreFormatsInMetadata = new HashSet <string>(StringComparer.OrdinalIgnoreCase) { }, AllowFileExtensions = new HashSet <string>(StringComparer.OrdinalIgnoreCase) { "js", "ts", "tsx", "jsx", "css", "htm", "html", "shtm", "txt", "xml", "rss", "csv", "pdf", "jpg", "jpeg", "gif", "png", "bmp", "ico", "tif", "tiff", "svg", "avi", "divx", "m3u", "mov", "mp3", "mpeg", "mpg", "qt", "vob", "wav", "wma", "wmv", "flv", "swf", "xap", "xaml", "ogg", "ogv", "mp4", "webm", "eot", "ttf", "woff", "woff2", "map", "xls", "xla", "xlsx", "xltx", "doc", "dot", "docx", "dotx", "ppt", "pps", "ppa", "pptx", "potx", "wasm", "proto", "cer", "crt" }, CompressFilesWithExtensions = new HashSet <string>(), AllowFilePaths = new List <string> { "jspm_packages/**/*.json", //JSPM ".well-known/**/*", //LetsEncrypt }, ForbiddenPaths = new List <string>(), DebugAspNetHostEnvironment = Env.IsMono ? "FastCGI" : "IIS7", DebugHttpListenerHostEnvironment = Env.IsMono ? "XSP" : "WebServer20", EnableFeatures = Feature.All, WriteErrorsToResponse = true, ReturnsInnerException = true, DisposeDependenciesAfterUse = true, LogUnobservedTaskExceptions = true, HtmlReplaceTokens = new Dictionary <string, string>(), AddMaxAgeForStaticMimeTypes = new Dictionary <string, TimeSpan> { { "image/gif", TimeSpan.FromHours(1) }, { "image/png", TimeSpan.FromHours(1) }, { "image/jpeg", TimeSpan.FromHours(1) }, }, AppendUtf8CharsetOnContentTypes = new HashSet <string> { MimeTypes.Json, }, RouteNamingConventions = new List <RouteNamingConventionDelegate> { RouteNamingConvention.WithRequestDtoName, RouteNamingConvention.WithMatchingAttributes, RouteNamingConvention.WithMatchingPropertyNames }, MapExceptionToStatusCode = new Dictionary <Type, int>(), UseSaltedHash = false, FallbackPasswordHashers = new List <IPasswordHasher>(), UseSameSiteCookies = false, UseSecureCookies = true, // good default to have, but needed if UseSameSiteCookies=true AllowSessionIdsInHttpParams = false, AllowSessionCookies = true, RestrictAllCookiesToDomain = null, DefaultJsonpCacheExpiration = new TimeSpan(0, 20, 0), MetadataVisibility = RequestAttributes.Any, Return204NoContentForEmptyResponse = true, AllowJsConfig = true, AllowPartialResponses = true, AllowAclUrlReservation = true, AddRedirectParamsToQueryString = false, RedirectToDefaultDocuments = false, RedirectDirectoriesToTrailingSlashes = true, StripApplicationVirtualPath = false, ScanSkipPaths = new List <string> { "obj/", "bin/", "node_modules/", "jspm_packages/", "bower_components/", "wwwroot_build/", #if !NETSTANDARD2_0 "wwwroot/", //Need to allow VirtualFiles access from ContentRoot Folder #endif }, RedirectPaths = new Dictionary <string, string> { { "/metadata/", "/metadata" }, }, IgnoreWarningsOnPropertyNames = new List <string> { Keywords.Format, Keywords.Callback, Keywords.Debug, Keywords.AuthSecret, Keywords.JsConfig, Keywords.IgnorePlaceHolder, Keywords.Version, Keywords.VersionAbbr, Keywords.Version.ToPascalCase(), Keywords.ApiKeyParam, Keywords.Code, Keywords.Redirect, Keywords.Continue, "s", "f" }, XmlWriterSettings = new XmlWriterSettings { Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false), }, FallbackRestPath = null, UseHttpsLinks = false, UseJsObject = true, EnableOptimizations = true, #if !NETSTANDARD2_0 UseCamelCase = false, #else UseCamelCase = true, #endif }; Platform.Instance.InitHostConfig(config); return(config); }
/// <summary> /// Initializes the AppHost. /// Calls the <see cref="Configure"/> method. /// Should be called before start. /// </summary> public virtual ServiceStackHost Init() { if (Instance != null) { throw new InvalidDataException($"ServiceStackHost.Instance has already been set ({Instance.GetType().Name})"); } Service.GlobalResolver = Instance = this; if (ServiceController == null) { ServiceController = CreateServiceController(ServiceAssemblies.ToArray()); } Config = HostConfig.ResetInstance(); OnConfigLoad(); AbstractVirtualFileBase.ScanSkipPaths = Config.ScanSkipPaths; ResourceVirtualDirectory.EmbeddedResourceTreatAsFiles = Config.EmbeddedResourceTreatAsFiles; Config.DebugMode = GetType().GetAssembly().IsDebugBuild(); OnBeforeInit(); ServiceController.Init(); BeforeConfigure.Each(fn => fn(this)); Configure(Container); AfterConfigure.Each(fn => fn(this)); if (Config.StrictMode == null && Config.DebugMode) { Config.StrictMode = true; } if (!Config.DebugMode) { Plugins.RemoveAll(x => x is RequestInfoFeature); } ConfigurePlugins(); List <IVirtualPathProvider> pathProviders = null; if (VirtualFileSources == null) { pathProviders = GetVirtualFileSources().Where(x => x != null).ToList(); VirtualFileSources = pathProviders.Count > 1 ? new MultiVirtualFiles(pathProviders.ToArray()) : pathProviders.First(); } if (VirtualFiles == null) { VirtualFiles = pathProviders?.FirstOrDefault(x => x is FileSystemVirtualFiles) as IVirtualFiles ?? GetVirtualFileSources().FirstOrDefault(x => x is FileSystemVirtualFiles) as IVirtualFiles; } OnAfterInit(); LogInitComplete(); HttpHandlerFactory.Init(); return(this); }
public static HostConfig NewInstance() { var config = new HostConfig { WsdlServiceNamespace = DefaultWsdlNamespace, ApiVersion = "1.0", EmbeddedResourceSources = new List <Assembly>(), EmbeddedResourceBaseTypes = new[] { HostContext.AppHost.GetType(), typeof(Service) }.ToList(), EmbeddedResourceTreatAsFiles = new HashSet <string>(), LogFactory = new NullLogFactory(), EnableAccessRestrictions = true, WebHostPhysicalPath = "~".MapServerPath(), HandlerFactoryPath = ServiceStackPath, MetadataRedirectPath = null, DefaultContentType = null, PreferredContentTypes = new List <string> { MimeTypes.Html, MimeTypes.Json, MimeTypes.Xml, MimeTypes.Jsv }, AllowJsonpRequests = true, AllowRouteContentTypeExtensions = true, AllowNonHttpOnlyCookies = false, UseHttpsLinks = false, DebugMode = false, DefaultDocuments = new List <string> { "default.htm", "default.html", "default.cshtml", "default.md", "index.htm", "index.html", "default.aspx", "default.ashx", }, GlobalResponseHeaders = new Dictionary <string, string> { { "Vary", "Accept" }, { "X-Powered-By", Env.ServerUserAgent }, }, IgnoreFormatsInMetadata = new HashSet <string>(StringComparer.OrdinalIgnoreCase), AllowFileExtensions = new HashSet <string>(StringComparer.OrdinalIgnoreCase) { "js", "ts", "jsx", "css", "htm", "html", "shtm", "txt", "xml", "rss", "csv", "pdf", "jpg", "jpeg", "gif", "png", "bmp", "ico", "tif", "tiff", "svg", "avi", "divx", "m3u", "mov", "mp3", "mpeg", "mpg", "qt", "vob", "wav", "wma", "wmv", "flv", "swf", "xap", "xaml", "ogg", "mp4", "webm", "eot", "ttf", "woff", "woff2", "map" }, DebugAspNetHostEnvironment = Env.IsMono ? "FastCGI" : "IIS7", DebugHttpListenerHostEnvironment = Env.IsMono ? "XSP" : "WebServer20", EnableFeatures = Feature.All, WriteErrorsToResponse = true, ReturnsInnerException = true, DisposeDependenciesAfterUse = true, MarkdownOptions = new MarkdownOptions(), MarkdownBaseType = typeof(MarkdownViewBase), MarkdownGlobalHelpers = new Dictionary <string, Type>(), HtmlReplaceTokens = new Dictionary <string, string>(), AddMaxAgeForStaticMimeTypes = new Dictionary <string, TimeSpan> { { "image/gif", TimeSpan.FromHours(1) }, { "image/png", TimeSpan.FromHours(1) }, { "image/jpeg", TimeSpan.FromHours(1) }, }, AppendUtf8CharsetOnContentTypes = new HashSet <string> { MimeTypes.Json, }, RouteNamingConventions = new List <RouteNamingConventionDelegate> { RouteNamingConvention.WithRequestDtoName, RouteNamingConvention.WithMatchingAttributes, RouteNamingConvention.WithMatchingPropertyNames }, MapExceptionToStatusCode = new Dictionary <Type, int>(), OnlySendSessionCookiesSecurely = false, AllowSessionIdsInHttpParams = false, RestrictAllCookiesToDomain = null, DefaultJsonpCacheExpiration = new TimeSpan(0, 20, 0), MetadataVisibility = RequestAttributes.Any, Return204NoContentForEmptyResponse = true, AllowPartialResponses = true, AllowAclUrlReservation = true, AddRedirectParamsToQueryString = false, RedirectToDefaultDocuments = false, StripApplicationVirtualPath = false, ScanSkipPaths = new List <string> { "obj/", "bin/", "node_modules/", "bower_components/", "wwwroot/", "wwwroot_build/", }, IgnoreWarningsOnPropertyNames = new List <string> { Keywords.Format, Keywords.Callback, Keywords.Debug, Keywords.AuthSecret, Keywords.IgnorePlaceHolder, Keywords.Version, Keywords.VersionAbbr, Keywords.Version.ToPascalCase(), }, XmlWriterSettings = new XmlWriterSettings { Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false), } }; if (config.HandlerFactoryPath == null) { config.InferHttpHandlerPath(); } return(config); }
public virtual void InitHostConifg(HostConfig config) { }
public static HostConfig NewInstance() { var config = new HostConfig { MetadataTypesConfig = new MetadataTypesConfig(addDefaultXmlNamespace: "http://schemas.servicestack.net/types"), WsdlServiceNamespace = "http://schemas.servicestack.net/types", EmbeddedResourceSources = new[] { HostContext.AppHost.GetType().Assembly, typeof(Service).Assembly }.ToList(), LogFactory = new NullLogFactory(), EnableAccessRestrictions = true, WebHostPhysicalPath = "~".MapServerPath(), HandlerFactoryPath = ServiceStackPath, MetadataRedirectPath = null, DefaultContentType = null, AllowJsonpRequests = true, AllowRouteContentTypeExtensions = true, AllowNonHttpOnlyCookies = false, UseHttpsLinks = false, DebugMode = false, DefaultDocuments = new List <string> { "default.htm", "default.html", "default.cshtml", "default.md", "index.htm", "index.html", "default.aspx", "default.ashx", }, GlobalResponseHeaders = new Dictionary <string, string> { { "X-Powered-By", Env.ServerUserAgent } }, IgnoreFormatsInMetadata = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase), AllowFileExtensions = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase) { "js", "css", "htm", "html", "shtm", "txt", "xml", "rss", "csv", "pdf", "jpg", "jpeg", "gif", "png", "bmp", "ico", "tif", "tiff", "svg", "avi", "divx", "m3u", "mov", "mp3", "mpeg", "mpg", "qt", "vob", "wav", "wma", "wmv", "flv", "xap", "xaml", "ogg", "mp4", "webm", "eot", "ttf", "woff" }, DebugAspNetHostEnvironment = Env.IsMono ? "FastCGI" : "IIS7", DebugHttpListenerHostEnvironment = Env.IsMono ? "XSP" : "WebServer20", EnableFeatures = Feature.All, WriteErrorsToResponse = true, ReturnsInnerException = true, MarkdownOptions = new MarkdownOptions(), MarkdownBaseType = typeof(MarkdownViewBase), MarkdownGlobalHelpers = new Dictionary <string, Type>(), HtmlReplaceTokens = new Dictionary <string, string>(), AddMaxAgeForStaticMimeTypes = new Dictionary <string, TimeSpan> { { "image/gif", TimeSpan.FromHours(1) }, { "image/png", TimeSpan.FromHours(1) }, { "image/jpeg", TimeSpan.FromHours(1) }, }, AppendUtf8CharsetOnContentTypes = new HashSet <string> { MimeTypes.Json, }, RouteNamingConventions = new List <RouteNamingConventionDelegate> { RouteNamingConvention.WithRequestDtoName, RouteNamingConvention.WithMatchingAttributes, RouteNamingConvention.WithMatchingPropertyNames }, GlobalHtmlErrorHttpHandler = null, MapExceptionToStatusCode = new Dictionary <Type, int>(), OnlySendSessionCookiesSecurely = false, RestrictAllCookiesToDomain = null, DefaultJsonpCacheExpiration = new TimeSpan(0, 20, 0), MetadataVisibility = RequestAttributes.Any, Return204NoContentForEmptyResponse = true, AllowPartialResponses = true, AllowAclUrlReservation = true, RedirectToDefaultDocuments = false, StripApplicationVirtualPath = false, ScanSkipPaths = new List <string> { "/obj/", "/bin/", }, IgnoreWarningsOnPropertyNames = new List <string> { "format", "callback", "debug", "_", "authsecret" } }; if (config.HandlerFactoryPath == null) { config.InferHttpHandlerPath(); } return(config); }
/// <summary> /// Initializes the AppHost. /// Calls the <see cref="Configure"/> method. /// Should be called before start. /// </summary> public virtual ServiceStackHost Init() { if (Instance != null) { throw new InvalidDataException($"ServiceStackHost.Instance has already been set ({Instance.GetType().Name})"); } Service.GlobalResolver = Instance = this; RegisterLicenseKey(AppSettings.GetNullableString("servicestack:license")); if (ServiceController == null) { ServiceController = CreateServiceController(ServiceAssemblies.ToArray()); } Config = HostConfig.ResetInstance(); OnConfigLoad(); AbstractVirtualFileBase.ScanSkipPaths = Config.ScanSkipPaths; ResourceVirtualDirectory.EmbeddedResourceTreatAsFiles = Config.EmbeddedResourceTreatAsFiles; OnBeforeInit(); ServiceController.Init(); var scanAssemblies = new List <Assembly>(ServiceAssemblies); scanAssemblies.AddIfNotExists(GetType().Assembly); RunConfigureAppHosts(scanAssemblies.SelectMany(x => x.GetTypes()) .Where(x => x.HasInterface(typeof(IConfigureAppHost)))); BeforeConfigure.Each(fn => fn(this)); Configure(Container); AfterConfigure.Each(fn => fn(this)); RunConfigureAppHosts(scanAssemblies.SelectMany(x => x.GetTypes()) .Where(x => x.HasInterface(typeof(IPostConfigureAppHost)))); if (Config.StrictMode == null && Config.DebugMode) { Config.StrictMode = true; } if (!Config.DebugMode) { Plugins.RemoveAll(x => x is RequestInfoFeature); } ConfigurePlugins(); List <IVirtualPathProvider> pathProviders = null; if (VirtualFileSources == null) { pathProviders = GetVirtualFileSources().Where(x => x != null).ToList(); VirtualFileSources = pathProviders.Count > 1 ? new MultiVirtualFiles(pathProviders.ToArray()) : pathProviders.First(); } if (VirtualFiles == null) { VirtualFiles = pathProviders?.FirstOrDefault(x => x is FileSystemVirtualFiles) as IVirtualFiles ?? GetVirtualFileSources().FirstOrDefault(x => x is FileSystemVirtualFiles) as IVirtualFiles; } OnAfterInit(); PopulateArrayFilters(); LogInitComplete(); HttpHandlerFactory.Init(); foreach (var callback in AfterInitCallbacks) { callback(this); } ReadyAt = DateTime.UtcNow; return(this); }