AnonymousId icon indicating copy to clipboard operation
AnonymousId copied to clipboard

Value cannot be null. stringToEscape

Open wakawajaszi opened this issue 7 years ago • 7 comments

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.

wakawajaszi avatar Dec 19 '18 21:12 wakawajaszi

Hi,

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

patbush avatar Dec 20 '18 08:12 patbush

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

aleripe avatar Dec 20 '18 09:12 aleripe

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

wakawajaszi avatar Dec 20 '18 09:12 wakawajaszi

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.

patbush avatar Dec 20 '18 13:12 patbush

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!

aleripe avatar Dec 20 '18 15:12 aleripe

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

patbush avatar Dec 20 '18 19:12 patbush

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

aleripe avatar Dec 20 '18 21:12 aleripe