如何在c#3.0中的类文件中定义的函数内使用response.redirect

Lea*_*ing 5 c# asp.net error-handling

GetPageName(String PageFileName, String LangCode)在类文件中定义了一个简单的函数.我从default.aspx.cs文件中调用此函数,在此函数中,我无法使用Response.Redirect("Error.aspx")向用户显示已生成错误.

以下是Code的示例

public static string GetPageName(String PageFileName, String LangCode)
{
     String sLangCode = Request("Language");
     String pgName = null;
     if ( sLangCode.Length > 6)
     {
        Reponse.Redirect("Error.aspx?msg=Invalid Input");
     }
     else
     {
         try
         {            
             String strSql = "SELECT* FROM Table";

             Dataset ds = Dataprovider.Connect_SQL(strSql);

         }
         catch( Exception ex)
         {
            response.redirect("Error.aspx?msg="+ex.Message);
         }
     }
     return pgName;
}
Run Code Online (Sandbox Code Playgroud)

我可能在Business和Datalayer中定义了函数,我想在其中捕获错误并将用户重定向到Error页面.

adt*_*adt 14

HttpContext.Current.Response.Redirect("error.aspx");
Run Code Online (Sandbox Code Playgroud)

要使用它,你的程序集应该引用System.Web.