I have the following code in the global.asa file. The aim is to get the segments from the URL and then run codes accordingly.
protected void Application_BeginRequest(object sender, EventArgs e)
{
Uri uriAddress = new Uri(Request.Url.AbsoluteUri);
if (!String.IsNullOrEmpty(uriAddress.Segments[1]))
{
//do stuff
}
}
Unfortunately if there are no segments in the URL I get the error that "Index was outside the bounds of the array". How can I overcome this error?