Last post May 21, 2020 06:11 AM by didemyosunlu
May 15, 2020 08:45 AM|didemyosunlu|LINK
I am developing an application which including user register, login and some other stuff. I have "Remember Me" feature when user login. But I also have to log every visit of the user through a web service.
I tried protected override void Initialize(System.Web.Routing.RequestContext requestContext) on home page but it is called every time the page is called.
protected override void Initialize(System.Web.Routing.RequestContext requestContext)
I am using cookies so global.asax application_start is not working. Is there anyone who did something like that before_ What is the right approach for this?
May 15, 2020 09:43 AM|jiadongm|LINK
But I also have to log every visit of the user through a web service.
Why not log user visit in your login method? You can record user access information after he passes the authentication. Usually, one session only includes once user login.
May 15, 2020 10:49 AM|didemyosunlu|LINK
The main thing is I have also a User management Portal and in this portal a user can be blocked. So for example a user logged in the application with checking remember me checkbox. Did some stuff for a while and close the browser. After two days he/she came
back. But before that a Portal user blocked her/him. So when she/he open the application I check the user from cookies and is not null I put cookie to session and allow the user to continue as if he/she logged in. So I need to check when application open the
first time and also log this as if he/she logged in. So I need somewhere to check cookies and go to database to log this visit "Only once" through this visit.
I hope it is more clear now.
May 15, 2020 11:29 AM|PatriceSc|LINK
I put cookie to session
So if you find a valid cookie but it is not in Session already it means the user returns and this is where you could log that? Do you have a problem with this particular point?
May 15, 2020 11:31 AM|didemyosunlu|LINK
Yes and I have to do this just once when the user opens the application.
May 15, 2020 11:45 AM|PatriceSc|LINK
Ok you don't have any written any code for this? For now my understanding is that you are rolling your own authentication/remember feature (you could consider to use what ASP.NET offers out of the box later). So I believe you should :
May 15, 2020 12:34 PM|didemyosunlu|LINK
Yes but where to put this logging block. Because I will log this as a login. So I have to do this once.
I cant put in Home controller Index method or others because they can be called multiple times. I cant put in Application_Start() because there is no Cookies in there yet.
So I need a place where hit only once when user opens the applicaiton.
May 15, 2020 02:26 PM|bruce (sqlwork.com)|LINK
You need to a browser cookie with a sliding expiration that you check after authentication. If it not there count as login, and set the cookie. If asp.net core use middle ware, if classic, the global.asax, the on AuthorizeRequest.
if you have not extended session timeout, you can set a value in session.
May 18, 2020 06:20 AM|didemyosunlu|LINK
the global.asax, the on AuthorizeRequest.
But then for each request I will be logging as user login. I need to log this just once when user opens the browser.
May 18, 2020 07:07 AM|PatriceSc|LINK
It will run for each request. You'll just have an "if" statement that will check if your session variable is already set (in which case you can skip the whole block) or if you need to trigger this "remember me" logic...
May 21, 2020 06:11 AM|didemyosunlu|LINK
I tried to implement this but for example I close the appliation and open after 15 minutes. session is still there so I dont understand if the application open the first time or I am just navigating between pages. Any other suggestion?