ASP.net MVC Logging Page Views -
is there easy way log every page hit user. thinking sit within global.asax.cs file, can write db table url of page being hit.
i've found way complete problem seems fit purpose.
i use postauthenticaterequesthandler method, called every page hit. ignore empty path , "/" these not actual pages hit.
//in global.asax.cs file private void postauthenticaterequesthandler(object sender, eventargs e) { ///.../// string extension = this.context.request.currentexecutionfilepathextension; string path = this.context.request.currentexecutionfilepath; if (extension == string.empty && path != "/") { pagevisitedlogmodel pagevisitedlogmodel = new pagevisitedlogmodel { datevisited = datetime.now, ipaddress = this.context.request.userhostaddress, pageurl = this.context.request.rawurl, username = this.context.user.identity.name }; //then writes log datahelper.updatepagevisitedlog(pagevisitedlogmodel); } }
Comments
Post a Comment