Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7692249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:48:38+00:00 2026-05-31T20:48:38+00:00

How can we run a method before running each Action in MVC3? I know

  • 0

How can we run a method before running each Action in MVC3?

I know we can use the following method for OnActionExecuting :

public class ValidateUserSessionFilterAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
      ...
    }
}

But how can we run a method before ActionExecuting ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:48:39+00:00Added an answer on May 31, 2026 at 8:48 pm

    You’re looking for Controller.ExecuteCore().

    This function is called before each action calls. You can override it in a controller or a base controller. Example that sets culture base on cookies from Nadeem Afana:

       public class BaseController : Controller
       {
          protected override void ExecuteCore()
          {
             string cultureName = null;
             // Attempt to read the culture cookie from Request
             HttpCookie cultureCookie = Request.Cookies["_culture"];
             if (cultureCookie != null)
             {
                cultureName = cultureCookie.Value;
             }
             else
             {
                if (Request.UserLanguages != null)
                {
                   cultureName = Request.UserLanguages[0]; // obtain it from HTTP header AcceptLanguages
                }
                else 
                {
                   cultureName = "en-US"; // Default value
                }
             }
    
             // Validate culture name
             cultureName = CultureHelper.GetImplementedCulture(cultureName); // This is safe
    
    
             // Modify current thread's cultures            
             Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cultureName);
             Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
    
             base.ExecuteCore();
          }
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know how I can run a method in a separate thread?
Is there a well-designed method that can run my ruby program from anywhere? I
Someone can point me reliable method to run given application in different session of
Can I rerender a jsf ui component when a valuechangelistener method is run? The
I can run the server on my local machine and connect to it on
I can run commands like vacuumdb, pg_dump, and psql just fine in a script
I can run this command in SqlManager to detach the db ALTER DATABASE mydb
I can run RENAME TABLE student TO student_new ; The command is same and
I can run multi-queries with MYSQL v5 with extension PHP :mysqli. But with MYSQL
I'm currently using a homegrown method to run a process as a different user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.