Log User Session Start / End Times For Audit Trail - Global.ASAX?
Feb 1, 2010
My ASP.NET intranet web application uses Windows Authentication, and I would like to record the following details:
1) Windows ID
2) Session Start Time
3) Session Stop Time
4) URL being browsed to (optional)
I've got some basic code setup in "Session_Start" method of the Global.ASAX to log session start times (seen below), but that's it so far. I have the feeling this is a primitive approach and there are "better" ways of doing this. So I really have two questions:
1) Is this the right way to go about doing this? If not what are some other options?
2) If this is the right way, do I just need to drop some code in the "Session_End" method to record the time they exit, and thats a complete solution? Does this method always get called when they close the browser tab they have the site open in, or do they have to close the entire browser (I don't have logout functionality)? Any way users can skip over this session end method (or start for that case)?
Dim connsql As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("MyConnectionstring").ConnectionString)
Dim cmdsql As System.Data.SqlClient.SqlCommand = connsql.CreateCommand
cmdsql.CommandText = "BeginUserSession"
cmdsql.CommandType = Data.CommandType.StoredProcedure
Try
cmdsql.Parameters.Add("@windowsid", System.Data.SqlDbType.VarChar, 30, "windowsid")
cmdsql.Parameters("@windowsid").Value = Session("UserInfo").identity.name
If connsql.State <> System.Data.ConnectionState.Open Then connsql.Open()
cmdsql.ExecuteNonQuery()
connsql.Close()
Catch ex As Exception
Finally
If connsql.State <> Data.ConnectionState.Closed Then connsql.Close()
End Try
'Stored Proc records start time
View 3 Replies
Similar Messages:
Jan 12, 2011
i am new in asp.net form authentication and sessions
i would like to know how to save session in masterpage or in global.asax and how to clear session.
how to better handle session timeout by redirecting to a page.
this is my web.config session settings
<sessionState mode="InProc" cookieless="false" timeout="1"></sessionState>
code in my masterpage
[code].....
View 2 Replies
Jul 26, 2010
I want to insitate a class instance in the session start of the application. code below
if (Session["user"] != null)
Session["user"] = new user();
I have created the "user" class as a separte dll and referenced and imported the namespace.But still i get 'are u missing assembly reference' it is not problem in 1.1 but seems has a problem in 2.0
View 2 Replies
Jul 13, 2010
We are developing a web application using asp.net and sql server. We are required to do an Audit trail for the application. As I understand this, an audit trail would basically be for all the Inserts, Updates and Deletes on the data base right? Now the way to approach this is that I have an Audit Trail Table in the DB that populates after every insert,update or delete is fired (Manually writing the script within the DAL). However any DB changes directly fired from SQL Management studio will NOT be recorded (for obvious reasons :P).
To cater for that I could create a trigger and that takes care of everything. I also did some googling and found out that SQL server has the ability to do audit trail. However the problem with using triggers is that I will NOT get the user information that logged in the website. I will get the sql user but I dont give two hoots about that, I am concerned about the website user. A solution that I figured out was either
a) Have an audit trail from my web application and also have trigger set up. On the audit report, I simply show an audit log from web application and and audit log from sql server.Obvious problems with this approach: over head. Writing to two different sets of tables on EVERY DB CHANGE.
b) I have a column called UserId ON EVERY DB TABLE. Then I create a trigger to capture all the DB changes. I pass this userId on every table I change (insert,update,delete) and the get this id from the trigger.
Obvious setbacks: unneccesary userid column in every table I do appologize for the long post. Basically I need an audit log that does log all the db changes (including direct hack to db) but at the same times gives me user login information for those db changes that were made FROM the web application.
View 4 Replies
May 24, 2010
I have a question regarding the record audit trail with EF. Recently we have started working on a application that has to have an record audit trail.Just few tables have Guid as PK, the rest of them have Int32 standard Identity setup.
The quick solution we have found is to wire up an event handler on SavingChanges and get all Added, Deleted and Modified records. But the problem is that the Inserted records for the tables that have Int32 as PK are audited with PK value of 0.
the code for the event handler looks like this:
[Code]....
View 2 Replies
Oct 11, 2010
I want to implement audit trail in my project. This implies keeping track of changes made in DB and later generating a report for specific data.
I'm looking for solutions other than triggers as in to have a generic solution for DB Audit trail in my project.
We'll probably be using Entity Framework 4.0. I want to explore the audit trail capabilities for the same any pointers in this directions would be helpful. also any ideas for DB Audit trail if we use Enterprise Library Data Application Block. Note:SQL Server 2008 has auditing features, but we'll not be using the Enterprise version.
View 1 Replies
May 2, 2010
I am developing my application in asp.net 3.5 and sql server 2005, and I want to record the visitor info into my database, like once the visitor enter my website, I'll insert his browser details to the database. [It's not necessary that visitor login my website].
Now I am confused where to put my code, If I put insert function in every page_load then on every page it will execute and I'll not be able to get the exact number of visitor, visited my website. Shall I go with application_start in Global.asax ??
View 2 Replies
Jun 9, 2010
I am in the process of creating an audit trail system. Simple enough. Certain fields require audit trail. What is the best design concept to allow this to work in multiple applications without having to change much? I would of course leave it to the admin of the site to add what fields should be audited, but the logic is the problem. Would implementing the interface IComparable be a place to start? My initial thinking is to compare 2 arrays against eachother and do an insert of what fields are in question. Array1 are the fields in the form, array2 are the fields from the sql table that require auditing.
View 8 Replies
May 2, 2010
application start in global.asax file
View 6 Replies
Jan 13, 2010
Not using Cassini, but IIS7 to run an ASP.NET app.
The debug behavior is flakey. Sometimes it works, sometimes it doesn't. I was able to step into the application start event in global.asax but sometimes I can't.
Sometimes VS2008 opens the published global.asax so I have two instances of global.asax opened in VS, the source and the published.
I reset the AppDomain and IIS and I can't put my finger on why this is happening.
To add, while it won't go into application start, I have an OnChangeEventHandler event - it does step into the event handler.
View 1 Replies
Sep 14, 2010
I added the following code to global.asax to load up several session variable when a session starts. I'm assuming that when a page goes to use the variable that I should be
1) checking at the page level that the value is valid not 0 when its not expected to be 0, not a zero-length string when its expected to have a length
2) have code at the page level that sets the values if the values have not been set as when the Session timeout, ideally putting the code in a class derived from Page and then deriving all of my pages from the new class so that the code does not have to be repeated in every page
[Code]....
View 7 Replies
Mar 20, 2010
how to get sessions in the global.asax, but I still cant get it to work...for some reason my session throws NullExceptions..the sessions are set from another page add looks something like:
[Code]....
And once I try to get those session values I do the following in the Global.asax:
[Code]....
But as I said, for some reason I get a NullException once I try to get the values...and they do have the same session-name,so they shouldn't be null..
View 6 Replies
Dec 20, 2010
i dont know about Global.asax so give some information about it and also tell me about the implementation and use of session_start and session_end event. How to call Global.asax in our website.
View 5 Replies
Nov 15, 2010
I'm using VS2010 and created a simple asp. web forms application, using Development Server to test it. I try to store user data - queried from sql server - in the session, since I don't want to access database in every request. I'm using the 'Application_AuthenticateRequest' and the 'Session_Start' methods.
First round:
AuthenticateRequest called. The following code ran:
[Code]....
The _current variable is a private static field published through a static property. In the first round the Session is null, and I think it's ok because the Session_Start not called yet. The Session_Start looks like this:
protected void Session_Start(object sender, EventArgs e)
{
Session["EMPLOYEE_DATA"] = EmployeeFactory.Current;
}
In the next round the Session_Start is not called of course but in the AuthenticateRequest I can't access to the session. The HttpContext.Current.Session is null and the this.Session reference throw a HttpException says the "Session state is not available in this context".
However I can access the Session from any of the page_load events but it's a bad practice I think that I put authentication every page_load.
View 1 Replies
Apr 6, 2010
When i start the application, based on some condition in global.asax page,i wil redirect to login page.If i click the logout button,
there i vil be clear all session value. here i want to initiate new session value like Session["InitialLogin"]="Yes".
How can i get this value in global .asax page. If get that session value [i.e Session["InitialLogin"]="Yes"], i vil redirect to some other page.
I cant able to get session value in global.asax page.i always getting null value.
View 7 Replies
Aug 18, 2010
I have a method in one class file with defination like this which gets the user id of logged person.
public string GetUserID(HttpRequest req)
{ .... }
I need to call this method in global.asax and save that value in session. I need to use this session value i need to use this Session value and assign that to label in Masterpage. I did not use global.asax before. And what should be the input to method... i have seen only Request is have the returntype HttpRequest. So i thought of giving that.
View 1 Replies
Mar 26, 2010
I'm getting a very peculiar problem with my asp.net application, it took me an age to track down but I still don't know what is causing this behaviour.
If I set a session variable in the Application_PreRequestHandlerExecute event, then my external JavaScript files are ignored, and therfore causing a raft of errors. I have simplified the problem below.
E.g.
I have file called JScript.js containing the code:
function myAlert() {
alert("Hi World");
}
And in my Default.aspx file I reference the js with the code:
<script src="JScript.js" type="text/javascript"></script>
And in the body onload event I call the myAlert() function:
<body onload="myAlert()">
And finally in the Global.asax file:
Private Sub Application_PreRequestHandlerExecute(ByVal sender As Object, ByVal e As EventArgs)
HttpContext.Current.Session("myVar") = "MyValue"
End Sub
If you run the Default.aspx file you will see the js function isnt called, however, if you comment out the line of code Global.asax then the external js is called and the function executed when the page loads.
View 1 Replies
Mar 10, 2011
I am have declared a session variable in login page of my application. I want to access that session variable in Application_BeginRequest of global.asax file. But I am not able to do it. Could you please suggest how to access the session variable in my global.asax file
void Application_BeginRequest(Object sender, EventArgs args)
{
string language = HttpContext.Current.Application["language"].ToString();
}
View 2 Replies
Apr 8, 2010
I'm trying to use SESSION in my MVC application.I wrote following line in Global.asax in Application_Start() method file:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
//uzupełnij zmienne sesyjne
HttpContext.Current.Session["LOCATION_ID"] = 15;
RegisterRoutes(RouteTable.Routes);
}
I also enabled SessionState in Web.config by addind following line:
<sessionState mode="InProc" cookieless="false" timeout="120" />
And when I run the application I'm getting this exception:
Szczegły wyjątku: System.NullReferenceException: Odwołanie do obiektu nie zostało ustawione na wystąpienie obiektu.
Błąd źrdła:
[Code]....
Wiersz 31: //uzupełnij zmienne sesyjneWiersz 32: Wiersz 33: HttpContext.Current.Session["LOCATION_ID"] = 15;Wiersz 34: Wiersz 35: RegisterRoutes(RouteTable.Routes);
View 5 Replies
Sep 3, 2010
I have a custom class that pulls user information from a SQL Server table. Now that I'm expanding the site from a single page to others. I want to shift the code to the Session_Start event so that the information is always loaded when the site is accessed. How do I call my custom code from global.asax since its script and not a class.
View 5 Replies
Feb 5, 2010
Can I set the connection string for custom session state mode in global.asax file? I cannot hard code the connection string in the webconfig file. ,I will get the connection string at runtime,Can i set the connection string for custom sessionmode/sqlserver session mode in the global.asax file(like in application statrevent, or aquirerequeststate event.If YES How to do that?
View 1 Replies
Jan 4, 2011
how can I implement a Global Session in my ASP.NET 3.5 website in C# using Global.asax file ?
View 18 Replies
May 7, 2015
How to page redirect in Global.asax Session_End ?
View 1 Replies
Sep 30, 2010
I want to be able to log when a user ends their session on our application and record whether it was a sign out or a the session expired. I am using
cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));
to set a new sessionId on sign out, but when the session expires, the sessionId is reused if the browser instance is not closed. In my web.config I have used
<sessionState mode="InProc" timeout="1" cookieName="session" regenerateExpiredSessionId="true" />
but still get sessions reused. I can't kill the cookie in Session_end() because I don't have access because there is no HttpContext or request, so I can't reset it that way. how I can force a new sessionId from the Global.asax.cs file?
View 2 Replies
Dec 6, 2010
I have a custom provider for authenticaiton that is HTTP Module-based. IIS authentication and web.config authentication is configure to 'None' and allow anonymous. When I probe for User.Identity.Name in Session_Start, it is empty. However User.Identity.Name works elswhere in the application as expected (returns the current user id). Is it possibly during Session_Start no authentication request has been issued, therefore there is no principal at this moment?
View 1 Replies