Click here to Skip to main content
15,925,528 members
Home / Discussions / C#
   

C#

 
AnswerRe: add number Pin
BobJanova24-Aug-11 4:16
BobJanova24-Aug-11 4:16 
AnswerRe: add number Pin
Luc Pattyn24-Aug-11 5:06
sitebuilderLuc Pattyn24-Aug-11 5:06 
Questionhow to simplify the loop? Pin
SRKSHOME23-Aug-11 23:15
SRKSHOME23-Aug-11 23:15 
AnswerRe: how to simplify the loop? Pin
Luc Pattyn24-Aug-11 0:14
sitebuilderLuc Pattyn24-Aug-11 0:14 
GeneralRe: how to simplify the loop? Pin
RobCroll24-Aug-11 1:39
RobCroll24-Aug-11 1:39 
AnswerRe: how to simplify the loop? Pin
V.24-Aug-11 0:38
professionalV.24-Aug-11 0:38 
AnswerRe: how to simplify the loop? Pin
PIEBALDconsult24-Aug-11 2:53
mvePIEBALDconsult24-Aug-11 2:53 
QuestionPrevent Multiple Login Pin
akosidandan23-Aug-11 18:31
akosidandan23-Aug-11 18:31 
Hello Experts,

I would like to ask if what are some easier ways preventing multiple log in of account to my web application.
I tried creating a flag field to my database that check the user if he or she is log in but its not good way because if he/she is not properly log out then the account will be lock and I will need to open his/her account manually. Done a couple of research but still I'm not able to.

Here is that code I manage to covert that previously in vb.net not sure though if my code 100% corrent or my conversion of the is ok. The code I managed to find is here http://forums.asp.net/t/1196897.aspx[^]

My code in Global.asax

C#
/// <summary>
       /// event fire when the user 1st browse the website
       /// </summary>
       protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)
       {
           //Response.Write("Fire up");

           //if session items is not null
           if (HttpContext.Current.Session != null)
           {
               Response.Write("SessionID:" + Session.SessionID.ToString() + "User Key:" +(string)Session["users"]);

               //fires after initial login
               if (Session["users"] != null)
               {


                  String sKey= (string)Session["users"];
                  string sUser = (String)HttpContext.Current.Cache[sKey];
               }
               //remove the cache item if session is over
               else
               {

                   foreach (DictionaryEntry dEntry in HttpContext.Current.Cache)
                   {
                       HttpContext.Current.Cache.Remove(dEntry.Key.ToString());
                   }

               }
           }



       }



Below is my code after the user successfully log in
C#
String sKey = Login1.UserName + Login1.Password;
                    string sUser = Convert.ToString(Cache[sKey]);

                    //no cache item
                    if (sUser == null || sUser==" ")
                    {


                        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"] = Login1.UserName + Login1.Password;
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("User is already Login");
                    }


After the code every time I login it always says that the user is already login now.


Stuck to my thesis because this Frown | :( D'Oh! | :doh:


Any Help is so much appreciated.
DANDAN

AnswerRe: Prevent Multiple Login Pin
Simon Bang Terkildsen23-Aug-11 20:13
Simon Bang Terkildsen23-Aug-11 20:13 
GeneralRe: Prevent Multiple Login Pin
akosidandan24-Aug-11 3:48
akosidandan24-Aug-11 3:48 
AnswerRe: Prevent Multiple Login Pin
Not Active24-Aug-11 2:16
mentorNot Active24-Aug-11 2:16 
GeneralRe: Prevent Multiple Login Pin
akosidandan24-Aug-11 2:41
akosidandan24-Aug-11 2:41 
GeneralRe: Prevent Multiple Login Pin
Not Active24-Aug-11 3:21
mentorNot Active24-Aug-11 3:21 
GeneralRe: Prevent Multiple Login Pin
akosidandan24-Aug-11 3:45
akosidandan24-Aug-11 3:45 
AnswerRe: Prevent Multiple Login Pin
BobJanova24-Aug-11 2:25
BobJanova24-Aug-11 2:25 
GeneralRe: Prevent Multiple Login Pin
akosidandan24-Aug-11 3:03
akosidandan24-Aug-11 3:03 
GeneralRe: Prevent Multiple Login Pin
Not Active24-Aug-11 3:18
mentorNot Active24-Aug-11 3:18 
GeneralRe: Prevent Multiple Login Pin
akosidandan24-Aug-11 3:31
akosidandan24-Aug-11 3:31 
GeneralRe: Prevent Multiple Login Pin
BobJanova24-Aug-11 4:13
BobJanova24-Aug-11 4:13 
AnswerRe: Prevent Multiple Login Pin
PIEBALDconsult24-Aug-11 2:58
mvePIEBALDconsult24-Aug-11 2:58 
GeneralRe: Prevent Multiple Login Pin
akosidandan24-Aug-11 3:21
akosidandan24-Aug-11 3:21 
QuestionC#.net working with windows authenication Pin
dcof23-Aug-11 12:14
dcof23-Aug-11 12:14 
AnswerRe: C#.net working with windows authenication Pin
Mycroft Holmes23-Aug-11 15:14
professionalMycroft Holmes23-Aug-11 15:14 
AnswerRe: C#.net working with windows authenication Pin
ake0123-Aug-11 23:29
ake0123-Aug-11 23:29 
AnswerRe: C#.net working with windows authenication Pin
Bernhard Hiller25-Aug-11 5:15
Bernhard Hiller25-Aug-11 5:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.