Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value cannot be null. stringToEscape #3

Open
wakawajaszi opened this issue Dec 19, 2018 · 7 comments
Open

Value cannot be null. stringToEscape #3

wakawajaszi opened this issue Dec 19, 2018 · 7 comments

Comments

@wakawajaszi
Copy link

wakawajaszi commented Dec 19, 2018

Hello,

I'm getting this error:

System.ArgumentNullException: Value cannot be null.
Parameter name: stringToEscape
   at System.Uri.EscapeDataString(String stringToEscape)
   at Microsoft.AspNetCore.Http.Internal.ResponseCookies.Append(String key, String value, CookieOptions options)
   at ReturnTrue.AspNetCore.Identity.Anonymous.AnonymousIdMiddleware.HandleRequest(HttpContext httpContext)
   at ReturnTrue.AspNetCore.Identity.Anonymous.AnonymousIdMiddleware.<Invoke>d__3.MoveNext()

This error occurs after the number of second I set up in AnonymousIdCookieOptionsBuilder -> SetCustomCookieTimeout

It looks like the code in AnonymousIdMiddleware on lines 86-98 doesn't work properly (maybe something wrong with bool SlidingExpiration value ) and can't attach a new cookie.

@patbush
Copy link

patbush commented Dec 20, 2018

Hi,

I'm getting exactly the same error. Do you find any solution for it?

@aleripe
Copy link
Owner

aleripe commented Dec 20, 2018

Currently trying to reproduce it... what version of Asp.NET Core are you on?

@wakawajaszi
Copy link
Author

Hi,
.net Core version is 2.1.4.
Try set SetCustomCookieTimeout to 120 and You should get error after 2 minutes.

@patbush
Copy link

patbush commented Dec 20, 2018

I found what is a problem and I have solution.
Problem:
Expire time is set once at start application and later never be updated.
Solution:
In the section where you recreate new id for anonymousId I was add
cookieOptions.Expires = DateTime.UtcNow.AddSeconds(cookieOptions.Timeout);
and after that problem was disappear.

@aleripe
Copy link
Owner

aleripe commented Dec 20, 2018

You were right... startup should contain only configuration options and not calculated ones. Moved the other into the middleware and should now be working!

Thanks for your feedback!

@patbush
Copy link

patbush commented Dec 20, 2018

I think you should add this code between 84 and 85 line. Now, every request calculate new expire date.

@aleripe
Copy link
Owner

aleripe commented Dec 20, 2018

Sliding expiration is enabled by default, but you can disable it by using CookieOptions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants