aravindb
aravindb

Reputation: 41

How to use public variable which used in whole ASP.NET web application

How to use public variable in Asp.NET with vb, in my web application i have class fils,aspx and asmx file, in this all pages i need access one public variable which i assign when user login, if i use session i cant access in asmx and class files, if i declare public variable in class file once page refresh it clear the assign values and became empty.

i want assign public variable with values and access in whole application until user logout, and once assign values when login it never change.

This is for connection sting , i know can declare in web conig, but we create each sql login for each and every user, so when user login we pass username to sql User ID

What I have tried:

For now i declare static variable and used in same page itself.If asp page no problem, but from class and asmx i need to each function connection strings.

Upvotes: 0

Views: 430

Answers (1)

Dan Dumitru
Dan Dumitru

Reputation: 5423

You can use Session for this, it works:

  1. in code-behind (classes) - https://learn.microsoft.com/en-us/previous-versions/ms178581(v=vs.140)
  2. in aspx files - Use Session variable in html
  3. in ASMX web services - Getting session in .NET ASMX web-service (thanks @AndrewMorton)

Upvotes: 3

Related Questions