-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EHD-1411: Reduce code in Core project: Move, rename HttpContextHelper…
… and stop using extension methods
- Loading branch information
1 parent
7d51f43
commit a21577b
Showing
3 changed files
with
51 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 48 additions & 47 deletions
95
...Core/Extensions/AspNetCore/HttpContext.cs → ...PayGap.WebUI/Helpers/HttpContextHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,48 @@ | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace System.Web | ||
{ | ||
public static class HttpContext | ||
{ | ||
|
||
public static void SetResponseCache(this Microsoft.AspNetCore.Http.HttpContext context, int maxSeconds) | ||
{ | ||
if (maxSeconds > 0) | ||
{ | ||
context.Response.Headers["Cache-Control"] = $"public,max-age={maxSeconds}"; | ||
} | ||
else | ||
{ | ||
context.Response.Headers["Cache-Control"] = $"no-cache,no-store,max-age=0,must-revalidate"; | ||
} | ||
} | ||
|
||
public static void SetResponseCookie(this Microsoft.AspNetCore.Http.HttpContext context, | ||
string key, | ||
string value, | ||
DateTime expires, | ||
string subdomain = null, | ||
string path = "/", | ||
bool httpOnly = false, | ||
bool secure = false) | ||
{ | ||
var cookieOptions = new CookieOptions { | ||
Expires = expires, | ||
Domain = subdomain, | ||
Path = path, | ||
Secure = secure, | ||
HttpOnly = httpOnly | ||
}; | ||
if (string.IsNullOrWhiteSpace(value)) | ||
{ | ||
context.Response.Cookies.Delete(key); | ||
} | ||
else | ||
{ | ||
context.Response.Cookies.Append(key, value, cookieOptions); | ||
} | ||
} | ||
|
||
} | ||
} | ||
using System; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace GenderPayGap.WebUI.Helpers | ||
{ | ||
public static class HttpContextHelper | ||
{ | ||
|
||
public static void SetResponseCache(HttpContext context, int maxSeconds) | ||
{ | ||
if (maxSeconds > 0) | ||
{ | ||
context.Response.Headers["Cache-Control"] = $"public,max-age={maxSeconds}"; | ||
} | ||
else | ||
{ | ||
context.Response.Headers["Cache-Control"] = $"no-cache,no-store,max-age=0,must-revalidate"; | ||
} | ||
} | ||
|
||
public static void SetResponseCookie(HttpContext context, | ||
string key, | ||
string value, | ||
DateTime expires, | ||
string subdomain = null, | ||
string path = "/", | ||
bool httpOnly = false, | ||
bool secure = false) | ||
{ | ||
var cookieOptions = new CookieOptions { | ||
Expires = expires, | ||
Domain = subdomain, | ||
Path = path, | ||
Secure = secure, | ||
HttpOnly = httpOnly | ||
}; | ||
if (string.IsNullOrWhiteSpace(value)) | ||
{ | ||
context.Response.Cookies.Delete(key); | ||
} | ||
else | ||
{ | ||
context.Response.Cookies.Append(key, value, cookieOptions); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters