Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8782729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:38:40+00:00 2026-06-13T20:38:40+00:00

In my asp.net web application i want to prevent multiple user login from the

  • 0

In my asp.net web application i want to prevent multiple user login from the same user name on different machine or the same pc by using Cache.So, in my Global.asax.as page,

i put this line…

protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
   {
     if (Session["user"] != null) // e.g. this is after an initial logon
     {
        string sKey = (string)Session["user"];
        string sUser = (string)HttpContext.Current.Cache[sKey];
     }
   }

and in my page login submit button click,

string userName=uName.Text;
string passWord=pwd.Text;

string sKey = uName.Text;
string sUser = Convert.ToString(Cache[sKey]);
if (sUser == null || sUser == String.Empty)
           {
               TimeSpan SessTimeOut = new TimeSpan(0, 0, HttpContext.Current.Session.Timeout, 0, 0);
               HttpContext.Current.Cache.Insert(sKey, sKey, null, DateTime.MaxValue, SessTimeOut, System.Web.Caching.CacheItemPriority.NotRemovable, null);
               Session["user"] = TextBox1.Text.Trim();

               if (userName.Equals(db_userName) && passWord.Equals(db_password))
               {
                   Response.Write("Welcome " + userName);
               }
               else
               {
                   Response.Write("Invalid Login");
               }
           }
           else
           {
               Response.Write("<Marquee><h1><font color=red>ILLEGAL LOGIN ATTEMPT!!!</font></h1></marquee>");
               return;
           }

But when run my application, It is raising Session state is not available in this context error message on Application_PreRequestHandlerExecute event…

I dont know what is the issue here…So, please guide me to get out of this issue…

Or tell me another good approach instead of this one…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:38:41+00:00Added an answer on June 13, 2026 at 8:38 pm

    Session state is not available during the initial request and may be null in subsequent requests. Check for null on session state object, not just the key/value.

    if(HttpContext.Current.Session!=null){
    //Proceed with xyz
    }
    

    Side note, Your use of Response.Write here…while not invalid, is atypical. I would suggest redirection to areas.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to retrieve yesterday's date in my ASP.NET web application using C#. I've
We want to split our large asp.net mvc web application into multiple Visual Studio
I am using an ASP.NET Web Application , I want to change this application
Am using the below message box in asp.net web application. Now i want to
I have an asp.net web-page application and i want it to be accessed using
I'm using a GridView in ASP.NET web application and want to open something like
I am building an ASP.Net web application and want to access data from MongoDB
I have an ASP.NET web application and I want to be able to take
I'm addressing a problem with an ASP .NET web application where I want to
I have created blank Asp.Net-MVC 3 web application and want to write my own

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.