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 5841857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:56:36+00:00 2026-05-22T11:56:36+00:00

I have a base Controller ApplicationController that needs to grab the URL Host and

  • 0

I have a base Controller ApplicationController that needs to grab the URL Host and do some processing before the child controllers are fired. Since controller constructors are fired before RequestContext is initialized I have to override Initialize method to do my processing.

ApplicationController:

    Protected Overrides Sub Initialize(ByVal requestContext As System.Web.Routing.RequestContext)
        MyBase.Initialize(requestContext)

        Dim host as String
        host = Request.Url.Host.ToString
    End Sub

What is the logic behind having Controller Constructors fire before the Initialize method?

Also what are the rules to what should be placed in the Initialize Method.

  • 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-22T11:56:37+00:00Added an answer on May 22, 2026 at 11:56 am

    Assuming that constructors are the first instance method ever to be fired in a .NET class, that shouldn’t come as a surprise and is not really something MVC specific. It’s more how the .NET framework works.

    The MVC framework needs to first instantiate a controller and then initialize it => it calls the constructor first. And because performing lots of code that could potentially might throw exceptions, etc… is not always best to be put in a constructor => the presence of the Initialize method. As far as this method is concerned I must admit that I have written lots of ASP.NET MVC code and never had to use it. Action filters always seemed like a better alternative.

    So to answer your question:

    Also what are the rules to what should be placed in the Initialize Method.

    I’ve never ever put any code and never ever need to override this method. I’ve always preferred using action filters because this way I am no longer in the obligation of deriving from a common base controller (not that this is a problem).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base URL : http://my.server.com/folder/directory/sample And a relative one : ../../other/path How
I have a base page, BasePage, that raises an event that displays messages to
I have a base class that represents a database test in TestNG, and I
I have a base class that has a private static member: class Base {
I have a base class vehicle and some children classes like car, motorbike etc..
I have a base class object array into which I have typecasted many different
I have a base class with an optional virtual function class Base { virtual
I have a base class with a property which (the get method) I want
I have a base class in which I want to specify the methods a
I have a base recipe class and I am using a datacontext. I overrode

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.