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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:48:02+00:00 2026-05-11T08:48:02+00:00

I’m experimenting with MVC, and my question is – where I had Page_Load logic

  • 0

I’m experimenting with MVC, and my question is – where I had Page_Load logic in Master Pages with WebForms, where should it go in MVC? Here’s the business case:

  • Different Host Headers should cause different Page Titles to be displayed on the site’s (one) Master Page, therefore all pages. For example, if the host header is hello.mydomain.com, the page title should be ‘Hello World’ for all pages/views, while goodbye.mydomain.com should be ‘Goodbye World’ for all pages/views.
  • If the host header is different than anything I have in the list, regardless of where in the application, it should redirect to /Error/NoHostHeader.

Previously, I’d put this in the MasterPage Load() event, and it looks like in MVC, I could do this either in every controller (doesn’t feel right to have to call this functionality in every controller), or somewhere in Global.asax (seems too… global?).

Edit: I have gotten this to work successfully using the Global.asax method combined with a Controller for actually processing the data. Only problem at this point is, all of the host header information is in a database. I would normally store the ‘tenant’ information if you will in a Session variable and only do a DB call when it’s not there; is there a better way to do this?

  • 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. 2026-05-11T08:48:03+00:00Added an answer on May 11, 2026 at 8:48 am

    There is no 1:1 equivalent in MVC for a reason, let’s just recapitulate how to think about it the MVC way:

    Model: ‘Pages of this site are always requested in a certain context, let’s call it the tenant (or user, topic or whatever your sub domains represent). The domain model has a property representing the tenant of the current request.’

    View: ‘Render the page title depending on the tenant set in the model.’

    Controller: ‘Set the tenant in the model depending on the host header’.

    Keep in mind that what we want to avoid is mixing controller, view and business logic. Having controller logic in more then one place or a place, that is not called ‘controller’ is not a problem, as long as it remains separated.

    And now the good thing: You could do this ‘MVC style’ even with Web Forms, and the solution still works with ASP.NET MVC!

    You still have the request lifecycle (not the page lifecycle), so you could implement a custom HttpModule that contains this part of the controller logic for all requests. It handles the BeginRequest event, checks for the host header, and stores the tenant to something like HttpContext.Current.Items[‘tenant’]. (Of course you could have a static, typed wrapper for this dictionary entry.)

    Then all your model objects (or a model base class, or whatever is appropriate for your solution) can access the HttpContext to provide access to this information like this:

    public string Tenant {     get { return HttpContext.Current.Items['tenant']; } } 

    Advantages:

    • You have separated cause (host header) and effect (rendering page title), improving maintainability and testability
    • Therefore you could easily add additional behavior to your domain model based on this state, like loading content from the database depending on the current tenant.
    • You could easily make more parts of the view depend on the tenant, like CSS file you include, a logo image etc.
    • You could later change the controller logic to set the tenant in the model not only based on the sub domain, but maybe based on a cookie, a referrer, search term, user agent’s language, or whatever you can think about, without modifying any of your code depending on the model.

    Update re your edit: I don’t like the idea of holding the state in the session, especially if your session cookie might apply not only to each sub domain, but to all domains. In this case you might serve inconsistent content if users visted another sub domain before. Probably the information in the database that is mapping host headers to tenants won’t change very often, so you can cache it and don’t need a database lookup for every request.

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

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer It basically boils down to the way the x86 handles… May 11, 2026 at 11:14 am
  • added an answer (1) The command list will most likely come from whatever… May 11, 2026 at 11:14 am
  • added an answer First, set a breakpoint at that line of the code… May 11, 2026 at 11:14 am

Related Questions

I keep getting tasks that are above my skill level. How can I address this without coming accross as grossly incompetent?
I have a web-service that I will be deploying to dev, staging and production.
I'm thinking of starting a wiki, probably on a low cost LAMP hosting account.
I have the following tables in my database that have a many-to-many relationship, which
I'm using the RESTful authentication Rails plugin for an app I'm developing. I'm having
I recently printed out Jeff Atwood's Understanding The Hardware blog post and plan on
I find that getting Unicode support in my cross-platform apps a real pain in
I would like to test a string containing a path to a file for
I'm getting this problem: PHP Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable
I'm an Information Architect and JavaScript developer by trade nowadays, but recently I've been

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.