aleripe / AnonymousId

Middleware for ASP.NET Core to enable the tracking of anonymous users

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Value cannot be null. stringToEscape

wakawajaszi opened this issue · 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.

Hi,

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

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

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

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.

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!

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

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