|
12 | 12 |
|
13 | 13 | builder.Services.AddRazorPages();
|
14 | 14 | var disableSession = Environment.GetEnvironmentVariable("DISABLE_SESSION");
|
15 |
| -if (string.IsNullOrEmpty(disableSession) || disableSession.ToLower() != "true") |
| 15 | +var sessionEnabled = string.IsNullOrEmpty(disableSession) || disableSession.ToLower() != "true"; |
| 16 | +if (sessionEnabled) |
16 | 17 | {
|
17 | 18 | builder.Services.AddSession(options =>
|
18 | 19 | {
|
|
61 | 62 | app.UseStaticFiles();
|
62 | 63 | app.UseRouting();
|
63 | 64 | app.UseAuthorization();
|
64 |
| -if (string.IsNullOrEmpty(disableSession) || disableSession.ToLower() != "true") |
| 65 | +if (sessionEnabled) |
65 | 66 | {
|
66 | 67 | app.UseSession();
|
67 | 68 | }
|
68 | 69 | app.Use(async (context, next) =>
|
69 | 70 | {
|
70 | 71 | var path = context.Request.Path;
|
71 | 72 | var isAccountPage = path.StartsWithSegments("/Account");
|
72 |
| - var isAuthenticated = context.Session.GetInt32("UserId").HasValue; |
73 |
| - |
| 73 | + var isAuthenticated = false; |
| 74 | + if (sessionEnabled) |
| 75 | + { |
| 76 | + isAuthenticated = context.Session.GetInt32("UserId").HasValue; |
| 77 | + } |
74 | 78 | if (!isAuthenticated && !isAccountPage && !path.StartsWithSegments("/Index"))
|
75 | 79 | {
|
76 | 80 | context.Response.Redirect("/Account/Login");
|
|
95 | 99 |
|
96 | 100 | builder.Services.AddRazorPages();
|
97 | 101 | var disableSession = Environment.GetEnvironmentVariable("DISABLE_SESSION");
|
98 |
| -if (string.IsNullOrEmpty(disableSession) || disableSession.ToLower() != "true") |
| 102 | +var sessionEnabled = string.IsNullOrEmpty(disableSession) || disableSession.ToLower() != "true"; |
| 103 | +if (sessionEnabled) |
99 | 104 | {
|
100 | 105 | builder.Services.AddSession(options =>
|
101 | 106 | {
|
|
144 | 149 | app.UseStaticFiles();
|
145 | 150 | app.UseRouting();
|
146 | 151 | app.UseAuthorization();
|
147 |
| -if (string.IsNullOrEmpty(disableSession) || disableSession.ToLower() != "true") |
| 152 | +if (sessionEnabled) |
148 | 153 | {
|
149 | 154 | app.UseSession();
|
150 | 155 | }
|
151 | 156 | app.Use(async (context, next) =>
|
152 | 157 | {
|
153 | 158 | var path = context.Request.Path;
|
154 | 159 | var isAccountPage = path.StartsWithSegments("/Account");
|
155 |
| - var isAuthenticated = context.Session.GetInt32("UserId").HasValue; |
156 |
| - |
| 160 | + var isAuthenticated = false; |
| 161 | + if (sessionEnabled) |
| 162 | + { |
| 163 | + isAuthenticated = context.Session.GetInt32("UserId").HasValue; |
| 164 | + } |
157 | 165 | if (!isAuthenticated && !isAccountPage && !path.StartsWithSegments("/Index"))
|
158 | 166 | {
|
159 | 167 | context.Response.Redirect("/Account/Login");
|
|
0 commit comments