protected System.Web.UI.Control LoadControl()
{
System.Web.UI.Control control; // Load a control that you want to show.Here is the path that you want to load from.
string controlPath = Globals.ApplicationPath + "/Module/Admin/" + ControlFileName.TrimStart('/');
string default_ControlPath = Globals.ApplicationPath + "/Module/" + ControlFileName.TrimStart('/'); // Do we have a control?
if ( ControlFileName == null )
{
throw new Exception("控件访问失败!错误原因:您没有指定控件!");
} // Now we attempt to load the control. If this fails, we're done.
try
{
control = Page.LoadControl(controlPath);
}
catch ( FileNotFoundException )
{
try
{
// If failed then load default path.
control = Page.LoadControl(default_ControlPath);
}
catch
{
// Ok, if we couldn't find the control, then throw a new exception of "FileNotFoundException".
throw new Exception("加载控件失败!错误原因:没有找到所指定路径的控件!");
}
}
// Finally, return the result:
return control;
}
上面这是程序代码
代码是处理N层结构中的,加载.ascx文件的功能的。 做过N层结构的,相信都是很了解的。
---------------------------------------------------------------------------
此代码的意图是第一个try出错后,就运行第二个try,该程序代码在vs2003运行通过,vs2005也运行通过。在vs2003编译后,运行无错,可以正常处理错误。
但是经过vs2005运行通过后,在前台显示的时候,发生以下错误:
-----------------------------------------
文件“/Web2/Module/Admin/SiteConfig/SLeft.ascx”不存在。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Web.HttpException: 文件“/Web2/Module/Admin/SiteConfig/SLeft.ascx”不存在。源错误: 
行 56:  try
行 57:  {
行 58:  control = Page.LoadControl(controlPath);
行 59:  }
行 60:  catch ( FileNotFoundException )
 
-------------------------------------------------------
提示文件路径出错。
正确的路径应是:“/Web2/Module/SiteConfig/SLeft.ascx”少一个"Admin/".明显的,通过程序中的错误处理机制,我可以让它生成正确的路径的,也就说,通过程序错误处理,我可以让他,因为第一个路径如果出错,我的错误处理会让它进行第二次try catch。 但是vs2005编译后的代码不会进行第二次try catch。
--------------------------------------------------------在系统给出的出错描述中,说的是System.Web.HttpException异常。 可是我把代码改成
try
{}
catch(System.Web.HttpException)
{}
后,问题依然存在。错误描述也一样还是上面的那个。
------------------------------------------------------请问此问题怎么解决。