Created
December 2, 2016 20:22
-
-
Save rionmonster/240cbe44b6875f179e9687606efe6782 to your computer and use it in GitHub Desktop.
Example with Possible NHibernate Implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AuditAttribute : ActionFilterAttribute | |
{ | |
public override void OnActionExecuting(ActionExecutingContext filterContext) | |
{ | |
//Stores the Request in an Accessible object | |
var request = filterContext.HttpContext.Request; | |
//Generate an audit | |
Audit audit = new Audit() | |
{ | |
//Your Audit Identifier | |
AuditID = Guid.NewGuid(), | |
//Our Username (if available) | |
UserName = (request.IsAuthenticated) ? | |
filterContext.HttpContext.User.Identity.Name : "Anonymous", | |
//The IP Address of the Request | |
IPAddress = request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? request.UserHostAddress, | |
//The URL that was accessed | |
AreaAccessed = request.RawUrl, | |
//Creates our Timestamp | |
TimeAccessed = DateTime.UtcNow | |
}; | |
// Create your NHibernate session / repository here and | |
// save your audit object | |
//Finishes executing the Action as normal | |
base.OnActionExecuting(filterContext); | |
} | |
} |
@rionmonster nevermind i solved that problem, but sadly im now stuck on the second part(advanced audit) part of your project.
Im stuck at
var sessionIdentifier = string.Join("", MD5.Create().ComputeHash(Encoding.ASCII.GetBytes(request.Cookies[FormsAuthentication.FormsCookieName].Value)).Select(s => s.ToString("x2")));
Where it always gives me the exception:
Object reference not set to an instance of an object
Any ideas please?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@rionmonster Hey thanks so much for this, it worked, the info is stored into the db.
But now im having a problem to present the actual information from the db table to the view.
i am trying to show it with a list view.