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.
Keson KefonPosted Nov 11, 2010, 8:26 AM
Jean PaulPosted Nov 11, 2010, 2:24 AM
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.
Jean PaulPosted Nov 10, 2010, 10:32 AM
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"];