To read from a Web.Config file using C# is very easy to do. Let's say we have an appSettings tag in our Web.Config that holds the website title. Inside in our web.config you would have something like this:
To get .net to read this value all you need to do is add this to your code behind page on your site. Be sure to add the System.Web.Configuration namespace as this is not added by default.
using System.Web.Configuration;
//read in the SiteName tag from web.config
string MySiteName = WebConfigurationManager.AppSettings["SiteName"];
If you want more details on how to read from web.config please see my earlier post
here
You might also want to write to your web.config file to allow the end user to update this data. To do this you must ensure that the Network Service user (or the ASP.NET user on WinServer 03 or earlier) has modify permissions on your website root folder.
Without the correct permission you will get the following error if you try to add the code below:
An error occurred loading a configuration file: Access to the path 'c:\inetpub\wwwroot\yourwebsitefolder\py39wsfg.tmp' is denied.
Assuming you have setup the correct permissions this code below will allow your web app to write to the web.config file.
//update the SiteName tag in web.config with a new value
Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
config.AppSettings.Settings["SiteName"].Value = "New Site Name Value";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
a22811ea-04ee-41e1-b174-a5398b75b32a|1|5.0
Yesterday I wrote a post about how to achive a redirect for domain.com to www.domain.com using IIS 6. Today I will show you how easy it is to set this up for IIS 7 on Win Server 2008.
You should be aware that this install requires a reboot. Only install on your server if you are in a position to restart your server.
First thing you need to do is download the rewrite module for IIS 7 from Microsoft. The 32bit version is here and the 64bit version here.
Before you can install this module you need to stop some services running on your server. Open the command prompt (Start -> Run -> type cmd and press enter) and type: net stop was /y
Now double click on the file you just downloaded and install the product. It can take a few mins and look like it's after hanging but give it a moment and it will install for you. You will be prompted to restart your server. Do this now as without a restart IIS will give you a 503 HTTP error when attempting to display a webpage.
Once the server has restarted open IIS Manager and make sure that both your domain and relevant application pool have been restarted.
Open up your browser and test your site just to double check everything is ok after the install. You should find that everything is working as normal.
You can now put the following rule in your web.config file within the <system.webServer> tag:
Save and FTP the web.config file to your server. If you type in yourdomain.com (without www.) you should notice that it redirects you to www.yourdomain.com now.
For more information about rerouting your traffic you can visit the IIS site for more details. A great place to start is on the Rule with Rewrite Map page.
9209dbcf-61a2-4c54-9e2d-fe80adf51000|0|.0
If you have a SSL on your site chances are that you only want your visitors to go through your site on one particular domain. Let's say you own domain.com and you always want your visitors to go to www.domain.com when using your site. IIS 7 has a really cool rewrite module that you can use but IIS 6 users need to jump through some hoops to get this function working.
For this article I will assume that you have www.domain.com already setup on your server in IIS 6 and that you have setup your SSL to work on this domain. I will also assume that you have setup the host name for your domain to be www.domain.com, your IP address and domain.com.
Your first step is to remove domain.com from the allowed host list for this domain in IIS. To do this just right click on domain.com in IIS and select Properties. Next to the IP address of your domain click the Advanced button. Highlight the host header that has domain.com (no www.) and click remove. Click OK and apply to save and continue.
At this point you might want to rename domain.com in IIS to say domain.com (WWW) to make it clear that this setup of domain.com is for www.domain.com.
Next up add a new domain to IIS. You should name this as domain.com (no WWW) in IIS, again this is only to make it clear when you're looking through your list of domains that this setup is for domain.com without the www. subdomain. Set this up exactly the same as you did for www.domain.com but put domain.com as the host name. Once you have added domain.com to IIS go to its properties and select the Home Directory tab.
- Select Redirect to another domain (1).
- Remove the application name (2).
- Enter in the domain we want to redirect to. In this case it's www.domain.com and add on $S$Q at the end of the domain so that you are specifying to IIS to redirect to the correct folder structure on www.domain.com and to pass through the correct query string values as entered by the user (3).
- Tick the checkboxes for The exact URL entered above and Permanent Redirect (4,5).
- Click Apply and then OK (6,7).

If you now open your browser and type in domain.com it should automatically redirect you to www.domain.com! If you test with query string values you should see that these also carry through to www.domain.com.
Although this option is not an ideal setup as it duplicates your IIS domain list it will work for you. If anyone knows a better way to achieve the same results in IIS 6 let me know.
ec758161-3392-4726-a06e-347b4724a2ec|0|.0

It might be the first day of December but that hasn't stop us from launching 2 new websites to get our December releases off to a great start! Aquatech Ireland have launched 2 new online stores and a brochure site to open up their products to customers all around the world. Aquatech.ie are one of Irelands leading suppliers of renewable energy systems and alternative heating solutions. With renewable energy on everyone's lips at the moment I'm sure they will do very well for themselves. TheHeatingWarehouse.co.uk is a sister site of aquatech specifically targeting the UK market. This site isn't live just yet but should be launched in the next few days. The PolarBear.ie brochure site is a nice little springboard site to links to both of these new stores.
Over the coming weeks we have loads of new and exciting sites launching including a new online clothing store for Clintons, a new online wine store for Vanilla Grape Wines, the new redesigned City Gate Mahon and much more. My blog has suffered a bit due to two massive projects that I am currently working on. I'll have more details on this work closer to launch but I've been learning loads about Google Maps and highly scalable server setups as a result of these projects. Fun times :D
5284de0c-8082-4770-8156-c17cbfb24cf1|0|.0