Skip to content

Commit b00ed5f

Browse files
committed
Fix session Cookie creation to respect HostContext.Config.RestrictAllCookiesToDomain in .NET Core
1 parent 3e88830 commit b00ed5f

File tree

1 file changed

+1
-54
lines changed

1 file changed

+1
-54
lines changed

src/ServiceStack/Host/Cookies.cs

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ public abstract class Cookies : ICookies
1515

1616
public static Cookies CreateCookies(IHttpResponse httpRes)
1717
{
18-
#if NETSTANDARD1_6
19-
if (httpRes?.OriginalResponse is Microsoft.AspNetCore.Http.HttpResponse)
20-
{
21-
return new NetCoreCookies(httpRes);
22-
}
23-
#endif
2418
return new NetCookies(httpRes);
2519
}
2620

@@ -80,53 +74,6 @@ public override void DeleteCookie(string cookieName)
8074
}
8175
}
8276

83-
#if NETSTANDARD1_6
84-
public class NetCoreCookies : Cookies
85-
{
86-
private readonly Microsoft.AspNetCore.Http.HttpResponse response;
87-
88-
public NetCoreCookies(IHttpResponse response)
89-
: this((Microsoft.AspNetCore.Http.HttpResponse)response.OriginalResponse){}
90-
91-
public NetCoreCookies(Microsoft.AspNetCore.Http.HttpResponse response)
92-
{
93-
this.response = response;
94-
}
95-
96-
public override void DeleteCookie(string cookieName)
97-
{
98-
response.Cookies.Delete(cookieName);
99-
}
100-
101-
public override void AddPermanentCookie(string cookieName, string cookieValue, bool? secureOnly = null)
102-
{
103-
var options = new Microsoft.AspNetCore.Http.CookieOptions
104-
{
105-
Path = RootPath,
106-
Expires = DateTime.UtcNow.AddYears(20)
107-
};
108-
if (secureOnly != null)
109-
{
110-
options.Secure = secureOnly.Value;
111-
}
112-
response.Cookies.Append(cookieName, cookieValue, options);
113-
}
114-
115-
public override void AddSessionCookie(string cookieName, string cookieValue, bool? secureOnly = null)
116-
{
117-
var options = new Microsoft.AspNetCore.Http.CookieOptions
118-
{
119-
Path = RootPath,
120-
};
121-
if (secureOnly != null)
122-
{
123-
options.Secure = secureOnly.Value;
124-
}
125-
response.Cookies.Append(cookieName, cookieValue, options);
126-
}
127-
}
128-
#endif
129-
13077
public static class CookiesExtensions
13178
{
13279
private static readonly DateTime Session = DateTime.MinValue;
@@ -159,7 +106,7 @@ public static CookieOptions ToCookieOptions(this Cookie cookie)
159106
var cookieOptions = new CookieOptions
160107
{
161108
Path = cookie.Path,
162-
Expires = cookie.Expires,
109+
Expires = cookie.Expires == DateTime.MinValue ? (DateTimeOffset?)null : cookie.Expires,
163110
HttpOnly = !HostContext.Config.AllowNonHttpOnlyCookies || cookie.HttpOnly,
164111
Secure = cookie.Secure
165112
};

0 commit comments

Comments
 (0)