Web.Config to redirect
Dear all, I just started learning c# and it has been challenging but fun. I have wrote a .Net app to request user's url and respond to them to a different url. See the attached code. I need to use web.config to create a list of these url redirects so I dont have to mess with the Redirect.aspx.cs file.

Jean PaulRank #32 · 38.5K reputationPosted Nov 10, 2010, 5:32 AM EST
You can use the appsettings section of web.config file.
Add a new Application configuration file and place code under the
(Please see config file attached)
You can read the setting from your page as following:
string url1 = ConfigurationManager.AppSettings["url1"];
string url2 = ConfigurationManager.AppSettings["url2"];
Jean PaulRank #32 · 38.5K reputationPosted Nov 10, 2010, 9:24 PM EST
After adding the Global.asax to the project, open the file and inside the code window select "Application" from left dropdownlist,
then select BeginRequest from the right dropdown.
The code will look like:
protected void Application_BeginRequest(object sender, EventArgs e)
{
// Sample Code
if (HttpContext.Current.Request.Url.AbsoluteUri.Contains("Default.aspx"))
HttpContext.Current.Response.Redirect("newpage.aspx")
}
In the above method you can handle all the requests and redirect them based on your config file entries.
Keson Kefon3 reputationPosted Nov 11, 2010, 3:26 AM EST