'Axios requests using cookie to authenticate .net core User

I need to authenticate the user on the backend using the authentication cookie I have stored. I need to request API in Vue using axios requests and send cookie in those requests. The user should then be authenticated in the backend controller. I store the cookie as a whole:

public string GetOrchardAuthCookie()
{
    return new ChunkingCookieManager().GetRequestCookie(_httpContextAccessor.HttpContext, "orchauth_Default");
}

my axios request:

axios.get(apiUrl, {
        headers: {
            "orchauth_Default": mySavedCookie
        }
    })
        .then(response =>
        {
            this.categories = response;
        })
        .catch(this.errorHandle);

after the request is made and I stop the code in the controller, the user has 0 claims

How to make Axios request to authenticate User in asp .net core controller?



Solution 1:[1]

There is no problem to use null as initial value for reference types in Java. But there isn't any relevance between initialize a reference type as null and garbage collection. You should initialize aTestCopy as null to use in another scope like in your case in while.

Garbage collection is triggered whenever an object in memory is not pointed anymore by any reference.

When you assign a reference type to another reference type (if it is not immutable in this case), you made copy the memory address of that value. So when you can make a change in aTestCopy will be reflected to the reference aTest.

Solution 2:[2]

In Java, variables do not hold objects, only references to objects.

The lifetime of objects is largely independent of the lifetime of variables: Objects are created by executing new, and reclaimed once the program has relinquished all means of accessing them (i.e. the object is no longer reachable form the references the program holds).

Put differently, the first variable to hold a reference to an object holds no special significance. In particular, it does not determine the lifetime of that object. Any reference will keep the object alive, and there can be no such thing as an "out of scope" object.

Similarly, when you assign a variable of reference type, you are only assigning the reference, causing both variables to point to the same object, and to see any changes done to this object though the other variable.

If you want a new object, you must use new (or call a method that uses new).

In your case, I'd make sure that myMethodReturnsATesterArray returns a new array, referencing new Tester objects. Then, the objects created by separate iterations of the loop will exist independently, allowing the loop to reference both the old and new objects and do whichever comparision it deems appropriate, without having to fear that the invocation of myMethodReturnsATesterArray has somehow changed the previous object.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 meriton