Guilherme Martin
Guilherme Martin

Reputation: 847

How to clear javascript SessionStorage in C#

I have a system where I save temporary variables using sessionStorage (javascript).

How can I do to clean them in C # inside a controller?

Tried HttpContext.Session.Clear()

But I was unsuccessful, the variable remains active until I close the browser.

Upvotes: 0

Views: 2863

Answers (1)

baHI
baHI

Reputation: 1570

See @Sam Axe's answer.

HttpContext.Session.Clear() is .NET context (server side). The sessionStorage is JavaScript, so you have to call:

sessionStorage.clear();

on the client side, so in the JavaScript code, possibly on some event button click, etc.)

ref: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage

Upvotes: 1

Related Questions