Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using OnAppStart to determine the site's frosting

Posted on 2011-09-08
3
Medium Priority
?
350 Views
Last Modified: 2012-05-12
Nutshell:
How (or if) to use the Global.asa as a way to clone a series of sites with a common code base but varying front-end elements.

Bigger Picture:
I have a donut shop and have found that if I deploy a series of websites - one for each of the donut types I manufacture (myGlazedDonut.com; mySprinkledDonut.com; myPlainDonut.com, and so on) - I'm better able to serve the interests of my customers than if I host one central 'DonutsRUs.com' domain. (taken, darnit).

I'm thinking the best code reuse will be one backend tier that drives multiple websites, one per frosting option. So I'd like to code a webapp that understands which frosting facade to present based on which domain it's running within.

So if the app wakes up to find it's running in the 'myFrostedDonut.com' domain it knows to display 'sales@myFrostedDonut.com' for the email address, it knows which .jpgs to use for Banners and Footers, it knows which google-analytics code to use. It even knows that on the 'Contact Us' the reader will see: Hi, from your loyal friends at Plain Donuts. Did you know that plain donuts are much better for you than those fattening things found at places like myFrostedDonuts.com.

Point is there are a lot of different 'search/replace' types of operations taking place in code. Usually I've used the web.config to store global variables but the above scenario is more complex than just a database connection string - there are a lot of exception conditions to account for, not every property has a one-to-one relation to each other domain.

I'm thinking I want to add logic at the Global.asa but need to see some examples of how others have approached similar problems.

thx
0
Comment
Question by:juststeve
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Expert Comment

by:ivan_vagunin
ID: 36512355
Hi! There are many ways to accomplish what you want, first I would advise to keep reusable in a separate library.
Then, you can make different site look using different master pages or css classes while using the same code, the other option is to use variation controls (controls, that renders different content based on some condition).
If you prefer variation controls, then you can place mode param in web.config or Appliction param collection - these are most suitable places because they are available across all application. If you prefer not to use web.config, then you can init Application param in global.asax, based on current url, like this:

protected void Application_Start(object sender, EventArgs e)
{
    if(string.Compare(HttpContext.Current.Request.Url.Host, "myFrostedDonut.com", true) == 0)
   {
       HttpContext.Current.Application["SiteMode"]  = "Frosted";
   }
}

Then in your code you can read it like:
string mode = Application["SiteMode"] as string;
0
 

Author Comment

by:juststeve
ID: 36523898
I'm not clear on the difference between web.config-based vs your reference to variation controls. How is something created in global.asax less available than web.config?

thx
0
 
LVL 18

Accepted Solution

by:
ivan_vagunin earned 2000 total points
ID: 36524390
The web.config-based solution is not vs. variation controls. Instead, the variations can be implemented using web.config based parameters. Parameters declared in web.config and parameters in HttpContext.Application collection have the same scope - they are available at application scope. The difference is in the way you can read and modify the parameters. If you use HttpContext.Application you can set parameters programmatically only, if you use web.config then you can set parameters by editing web.config.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question