How to access Session variable in HTML Page

Adnaan
 
on Oct 10, 2021 01:33 PM
976 Views

Hi,

Please let me know how to access Session variable value in HTML Page?

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
Mudassar
 
on Oct 10, 2021 01:37 PM

Hi,

I am not sure what you are using?

Is it ASP.Net WebForms or MVC?

Anyways here is the solution.

Let's say you have a Session variable

Session["Name"] = "Mudassar";

Then you can display in HTML in following way

ASP.Net WebForms (ASPX Page)

<%=Session["Name"].ToString()%>

ASP.Net MVC (View)

@Session["Name"]

 

But if you want to access from plain HTML, then you need to do an AJAX call and access Session from Server