How to track time on page per user with application insights - asp.net-mvc

With asp.net core mvc, how does one track time on page per user? I.e I want to track how long a user stays on a page (or all pages)

Did you try autoTrackPageVisitTime property sir? I find it seems to meet your requirement and I tested it in my side. Here's the query log in application insights.

Related

Is there any way to bring an ASP.NET MVC application into "single user mode", rejecting new logins?

Is there a strategy/approach that can be built to bring an ASP.NET MVC application into "single user mode" gracefully? By "single user mode" I mean something that when activated will block all new user access/logins, but allow existing users to complete their sessions and log out.
SCENARIO: I need to republish an active MVC application during the day in order to patch errors. Since we are conducting a new release I need to be able to do these patches sometimes a few times a day to squash bugs. Our users are all over the world and I don't have the ability to contact them individually to tell them of the patch, especially if it is a quick fix that is needed. So far I've just been republishing which means for some users their sessions will be destroyed, they will get errors when trying to navigate from one screen or form to another, etc.
What I would like is a feature that will let me log in as the site admin (custom Identity auth), flip a switch, and from that point forward (unless I flip the switch again) no new logins will be accepted. I would also need the ability to monitor sessions and ideally mark individual sessions for termination immediately if necessary, which I'm not sure is possible out of the box at all.
If there is no NuGet package or at least some code sample out there that can do it I'm considering rolling my own. One approach is giving the app admin a screen to set a boolean Application variable that is then checked during each user's login. If that Application variable is true then the authentication logic redirects the user to a friendly message that logins are disabled. Session management would be trickier, maybe have the base controller update an Application variable (dictionary?) on each page load, and then the admin can view a screen that shows a list of those sessions and can flag them for termination? And then the next time a flagged user loads a screen the base controller logs them out since they were flagged for termination. But I'm not sure if there will be threading/deadlock/etc issues with everyone accessing this Application variable repeatedly like that.
For reference, the application is used by about 3-5K different users per day, about 25-30k screen/page views per day. Backend is a combination of Oracle and SQL Server but that shouldn't matter, unless it would be better to track the session info in the DB.
This is not a hard requirement, but the impact on the users when the site goes down can be severe, so I want to make it as graceful as possible. Right now it is crude.

Getting Number of connections currently viewing mvc3 application

MVC3 vb.net Application using built in session management. I have an mvc3 application that I would like to add being able to see the current number of users online to whether they are logged in or not. I have tried using:
Membership.GetNumberOfUsersOnline.ToString
But that only keeps track of current users logged in which is not acceptable in what I am trying to do. Is there any other method that keeps track of connections????
You could hook on the Session_Start and Session_End events in global.asax. Increase a counter in Session_Start and decrease it in Session_End.
Or you can read this article on how to read all users session state via a dirty reflection hack. So you don't have to count yourself.

A web app with logins in a kiosk situation

We are looking at setting up an internal web application (ASP.NET MVC) as a kiosk for the employees that don't have a dedicated computer. We currently do not have this kiosk setup. Each employee will have their own login to look at some basic payroll information and request leaves of absence. This same web application will be used by the office workers with a dedicated PC at their desk.
I am going to go out on a limb and say that no matter how many times we tell the employees, the employees will not click log off when they walk away from the kiosk. What would you do to help prevent this from happening?
lets try to fix the users instead of the code :) , i guess that your log out button is like the one here on stackoverflow. its a little text link "logout" some where in the upper right corner. thats perfect for people who use webapps day by day and are aware of the fact that they need to logout before someone comes along a does havoc to thier facebook profile, but less tech savy users wont think of that and walk away.
you need to the get the attention of your users to this logout-button and teach them that logging-out is a good thing.
try the following
give the logout button more visual weight then usally make it bigger, make it a real button instead of a textlink and even change its color to something more alerting (red, orange, ... whatever fits your ci)
if they dont loggout, use the session timeout and some javascript the refresh the page after any amount of inactivity, but also set a flag that this user has not logged out after his last visit. that way you can greet him on his next login with a nice confirmation dialog, and tell him once again why logging out is so important and where your logout-button is located.
The naive solution would be to enforce a timeout. If there's no activity from the user within a certain time limit (say, a minute or so), log them out. Of course, this won't prevent someone from walking up immediately after an employee is done and seeing how much money they make.
ATMs handle this, I think, by timing out after a minute or two, which isn't super-secure but at least offers some minimal security.
If the employees have any kind of RFID card or other security token, you could require them to put it in a reader slot, and log them out whenever the card disappears. Handling this within a web app, though, could get complicated.
The simple way is to use a little javascript.
Just have it set to something like 30 seconds of inactivity. If the user hasn't clicked on anything have the javascript send it back to a login page.
Here's a link to get you started.
Assuming you've already thought of the obvious (aggressive session timeouts, non-persistent authentication cookies, etc); how about a bit of an "out there" suggestion?
I'm not sure how do-able this would be with a web-based interface; but what about using some form of IR sensor with a usb/serial interface and an API you can tie into? This may make it possible to invoke some form of "logout" operation when someone walks away from the kiosk.
Perhaps someone has a better suggestion for external hardware, but this was the first thing that lept to my mind as a out-of-the-box approach.
I found a jQuery version that seems to work quite well. I'll start by using that and see how that goes.

Determine the view count like in youtube using Asp.net MVC

Do anyone knows how to do the View count for a specific page.
Like in youtube, when you click a video, the number of view count will increment. But if you already viewed the video before it will not increment.
I would like to know how to do this in asp.net mvc. I already have an idea but im not sure if right.
I need an expert advice... thanks
You would probably need to store the total view count in a db and as serbrech said use a cookie to determine if the user has been to the page before and if not increment the view count.
I would simply store a permanent cookie on the user...
Though, that would be reset when the user deletes it.

MVC Web Application Database Driven Menu by User Permissions

We are going to port a legacy windows app to a large web application for a vertical market. Looking at MVC. Each implementation may have 50 to 5000 users. Looking at putting navigation in Master Page. The application will contain 200 to 300 menu items, resulting in over 500 views. We want to display a trimmed navigation menu for each user based on their application permissions. A user may see only 20 items, or all available.
Most posts I have seen suggest passing navigation items to Master Page through viewdata, established in a base controller class. I understand this.
Each of the potentially 10's to 1000's of users will have a different set of permissions.
Does anyone have any solutions that will avoid hitting the database to get the users menu items on every controller request that inherits from the base controller?
Is there a caching scheme that will work for each user?
Should the navigation be handled in a frame (not my choice)?
Is this just a price we will pay for this approach to navigation?
Thanks for any input!
You could start by caching linq queries which would be a nice way to tackle this at the DB tier.
Doing this in MVC using an action filter wouldn't be too hard either.
I implemented something like this in PHP a year ago but the general idea is the same. Firstly, you'll need to assign each menu configuration a unique id. This way when user A and user X request the same menu configuration, it resolves to the same cache file.
The first time a menu needs to be loaded for the user, it is loaded from the database and passed to the user. Simultaneously, it is saved to a cache file with the unique id in its name. On subsequent requests the action filter can load the data from the cache file if it exists and bypass the database.
Some ideas:
1.) You could have your nav bar html come from a Html.RenderAction (MVC Futures) and use the Output cache on that.
2.) You could generate the html for the nav bar per user then save that to the DB and regenerate if their user permissions change. So all you would need to do is pull the html from the DB against each users record.

Resources