20171

ASP.NET MVC 1 using persistent cookie, intercept loading of user data to include other logic

Question:

I am using Forms Authentication for the default MVC site, and i also have a custom DB table with extra user information (LINQ2SQL). I have some logic that loads the extra data from the db when the user logs in manually on the site, but the same logic is not executed when the users data is loaded from the persistent cookie stored when they logged in last.

At what point is that users data loaded, and how do i add my own logic during that event?

Answer1:

IN your global.asax you can hook into the PostAuthenticateRequest event.

<a href="http://msdn.microsoft.com/en-us/library/system.web.httpapplication.postauthenticaterequest.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.web.httpapplication.postauthenticaterequest.aspx</a>

protected void Application_Start() { } protected void Application_PostAuthenticateRequest(object sender, EventArgs e) { //do stuff with User.Identity here }

Recommend

  • firebase unauth with google doesn't allow change of user
  • Add log separators to all fixtures in unittests
  • Laravel 5.2 Auth::check() on exception pages (layouts)
  • System call time out?
  • Thread synchronization with syncwarp
  • You tube videos are not playing
  • Problem with Django using Apache2 (mod_wsgi), Occassionally is “unable to import from module” for no
  • Most efficient way to move table rows from one table to another
  • How can I run DataNucleus Bytecode Enhancer from SBT?
  • Jquery Knockout: ko.computed() vs classic function?
  • Servlet stops working on Tomcat server after some hits or time
  • TFS 2015 - Waiting for an agent to be requested
  • How do I display a dialog that asks the user multi-choice questıon using tkInter?
  • how does System.Web.HttpRequest::PathInfo work?
  • Loading .coffee files via a view in Rails
  • How can I extract results of aggregate queries in slick?
  • Needing to do .toArray() to get output of mongodb .find() on key name not value
  • Keep this build forever option - Jenkins
  • Converting a WriteableBitmap image ToArray in UWP
  • Test if a set exists before trying to drop it
  • Chrome doesn't support silverlight anymore? How to solve this?
  • C++ Partial template specialization - design simplification
  • MongoDB in PHP using aggregate to group by _id is null not working
  • Is there any way to access browser form field suggestions from JavaScript?
  • Android screen density dpi vs ppi
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • How would I use PHP exceptions to define a redirect?
  • Controls, properties, events and timers running in design time
  • script to move all files from one location to another location
  • How to extract text from Word files using C#?
  • Cassandra Data Model
  • ActionScript 2 vs ActionScript 3 performance
  • Hazelcast - OperationTimeoutException
  • Codeigniter doesn't let me update entry, because some fields must be unique
  • embed rChart in Markdown
  • need help with bizarre java.net.HttpURLConnection behavior
  • Turn off referential integrity in Derby? is it possible?
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app