3
3
| Client Ignia, LLC
4
4
| Project Sample OnTopic Site
5
5
\=============================================================================================================================*/
6
- using System ;
7
- using System . Diagnostics . CodeAnalysis ;
8
- using Microsoft . AspNetCore . Hosting ;
9
- using Microsoft . Extensions . Hosting ;
10
-
11
- namespace OnTopic . AspNetCore . Mvc . Host {
12
-
13
- /*============================================================================================================================
14
- | CLASS: PROGRAM
15
- \---------------------------------------------------------------------------------------------------------------------------*/
16
- /// <summary>
17
- /// The <see cref="Program"/> class—and it's <see cref="Program.Main(String[])"/> method—represent the entry point into the
18
- /// ASP.NET Core web application.
19
- /// </summary>
20
- [ ExcludeFromCodeCoverage ]
21
- public static class Program {
22
-
23
- /*==========================================================================================================================
24
- | METHOD: MAIN
25
- \-------------------------------------------------------------------------------------------------------------------------*/
26
- /// <summary>
27
- /// Responsible for bootstrapping the web application.
28
- /// </summary>
29
- public static void Main ( string [ ] args ) => CreateHostBuilder ( args ) . Build ( ) . Run ( ) ;
30
-
31
- /*==========================================================================================================================
32
- | METHOD: CREATE WEB HOST BUILDER
33
- \-------------------------------------------------------------------------------------------------------------------------*/
34
- /// <summary>
35
- /// Configures a new <see cref="IWebHostBuilder"/> with the default options.
36
- /// </summary>
37
- public static IHostBuilder CreateHostBuilder ( string [ ] args ) =>
38
- Microsoft . Extensions . Hosting . Host
39
- . CreateDefaultBuilder ( args )
40
- . ConfigureWebHostDefaults ( webBuilder => {
41
- webBuilder . UseStartup < Startup > ( ) ;
42
- } ) ;
43
-
44
- } //Class
45
- } //Namespace
6
+ using Microsoft . AspNetCore . Mvc . Controllers ;
7
+ using Microsoft . AspNetCore . Mvc . ViewComponents ;
8
+ using OnTopic . AspNetCore . Mvc ;
9
+ using OnTopic . AspNetCore . Mvc . Host ;
10
+
11
+ #pragma warning disable CA1812 // Avoid uninstantiated internal classes
12
+
13
+ /*==============================================================================================================================
14
+ | CONFIGURE SERVICES
15
+ \-----------------------------------------------------------------------------------------------------------------------------*/
16
+ var builder = WebApplication . CreateBuilder ( args ) ;
17
+
18
+ /*------------------------------------------------------------------------------------------------------------------------------
19
+ | Configure: Cookie Policy
20
+ \-----------------------------------------------------------------------------------------------------------------------------*/
21
+ builder . Services . Configure < CookiePolicyOptions > ( options => {
22
+ // This lambda determines whether user consent for non-essential cookies is needed for a given request.
23
+ options . CheckConsentNeeded = context => true ;
24
+ options . MinimumSameSitePolicy = SameSiteMode . None ;
25
+ } ) ;
26
+
27
+ /*------------------------------------------------------------------------------------------------------------------------------
28
+ | Configure: Output Caching
29
+ \-----------------------------------------------------------------------------------------------------------------------------*/
30
+ builder . Services . AddResponseCaching ( ) ;
31
+
32
+ /*------------------------------------------------------------------------------------------------------------------------------
33
+ | Configure: MVC
34
+ \-----------------------------------------------------------------------------------------------------------------------------*/
35
+ builder . Services . AddControllersWithViews ( )
36
+
37
+ //Add OnTopic support
38
+ . AddTopicSupport ( ) ;
39
+
40
+ /*------------------------------------------------------------------------------------------------------------------------------
41
+ | Register: Activators
42
+ \-----------------------------------------------------------------------------------------------------------------------------*/
43
+ var activator = new SampleActivator ( builder . Configuration . GetConnectionString ( "OnTopic" ) ) ;
44
+
45
+ builder . Services . AddSingleton < IControllerActivator > ( activator ) ;
46
+ builder . Services . AddSingleton < IViewComponentActivator > ( activator ) ;
47
+
48
+ /*==============================================================================================================================
49
+ | CONFIGURE APPLICATION
50
+ \-----------------------------------------------------------------------------------------------------------------------------*/
51
+ var app = builder . Build ( ) ;
52
+
53
+ /*------------------------------------------------------------------------------------------------------------------------------
54
+ | Configure: Error Pages
55
+ \-----------------------------------------------------------------------------------------------------------------------------*/
56
+ app . UseStatusCodePagesWithReExecute ( "/Error/{0}/" ) ;
57
+ if ( ! app . Environment . IsDevelopment ( ) ) {
58
+ app . UseExceptionHandler ( "/Error/500/" ) ;
59
+ // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
60
+ app . UseHsts ( ) ;
61
+ }
62
+
63
+ /*------------------------------------------------------------------------------------------------------------------------------
64
+ | Configure: Server defaults
65
+ \-----------------------------------------------------------------------------------------------------------------------------*/
66
+ app . UseHttpsRedirection ( ) ;
67
+ app . UseStaticFiles ( ) ;
68
+ app . UseCookiePolicy ( ) ;
69
+ app . UseRouting ( ) ;
70
+ app . UseCors ( "default" ) ;
71
+ app . UseResponseCaching ( ) ;
72
+
73
+ /*------------------------------------------------------------------------------------------------------------------------------
74
+ | Configure: MVC
75
+ \-----------------------------------------------------------------------------------------------------------------------------*/
76
+ app . MapImplicitAreaControllerRoute ( ) ; // {area:exists}/{action=Index}
77
+ app . MapDefaultAreaControllerRoute ( ) ; // {area:exists}/{controller}/{action=Index}/{id?}
78
+ app . MapTopicAreaRoute ( ) ; // {area:exists}/{**path}
79
+
80
+ app . MapTopicErrors ( includeStaticFiles : false ) ; // Error/{statusCode}
81
+ app . MapDefaultControllerRoute ( ) ; // {controller=Home}/{action=Index}/{id?}
82
+ app . MapTopicRoute ( rootTopic : "Web" ) ; // Web/{**path}
83
+ app . MapTopicRoute ( rootTopic : "Error" ) ; // Error/{**path}
84
+ app . MapTopicSitemap ( ) ; // Sitemap
85
+ app . MapTopicRedirect ( ) ; // Topic/{topicId}
86
+ app . MapControllers ( ) ;
87
+
88
+ /*------------------------------------------------------------------------------------------------------------------------------
89
+ | Run application
90
+ \-----------------------------------------------------------------------------------------------------------------------------*/
91
+ app . Run ( ) ;
92
+
93
+ #pragma warning restore CA1812 // Avoid uninstantiated internal classes
0 commit comments