我在global.asa文件中有以下代码。目标是从URL中获取分段,然后相应地运行代码。uriAddress.Segments [1]激发错误 - 索引超出了数组的范围
protected void Application_BeginRequest(object sender, EventArgs e)
{
Uri uriAddress = new Uri(Request.Url.AbsoluteUri);
if (!String.IsNullOrEmpty(uriAddress.Segments[1]))
{
//do stuff
}
}
不幸的是,如果有在我得到的错误是“索引数组的范围之外”的网址不段。我怎样才能克服这个错误?
'如果(uriAddress.Segments!= NULL && uriAddress.Segments.Length> 1 &&!String.IsNullOrEmpty(uriAddress.Segments [1]))' – Habib 2014-10-28 19:05:39