Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从自定义c#类调用response.redirect_C#_Asp.net_Response.redirect - Fatal编程技术网

如何从自定义c#类调用response.redirect

如何从自定义c#类调用response.redirect,c#,asp.net,response.redirect,C#,Asp.net,Response.redirect,我正在用asp.net编写一个web应用程序。用户输入他们的凭据,并根据实际的电子邮件地址和密码进行验证以进行授权。我编写了一些用于处理这些数据的类(在一个单独的.cs文件中) 但是,我似乎无法从单独的cs文件中的Login类内部访问Response.Redirect()方法。(我可以从我为aspx页面编写的事件处理程序中访问它。)有人有什么想法吗?提前感谢您的帮助 是的,因为您的方法是静态的(如果不是静态的,它将在代码中工作),所以您希望将响应传递给它,如下所示: public static

我正在用asp.net编写一个web应用程序。用户输入他们的凭据,并根据实际的电子邮件地址和密码进行验证以进行授权。我编写了一些用于处理这些数据的类(在一个单独的.cs文件中)


但是,我似乎无法从单独的cs文件中的Login类内部访问Response.Redirect()方法。(我可以从我为aspx页面编写的事件处理程序中访问它。)有人有什么想法吗?提前感谢您的帮助

是的,因为您的方法是静态的(如果不是静态的,它将在代码中工作),所以您希望将响应传递给它,如下所示:

public static void LoginFirstTime(string Email, 
                                  string Password, 
                                  HttpResponse Response)
{

for convention响应应更改为“Response”。

尝试使用完整命名空间:

public static void LoginFirstTime(string Email, string Password)
{
    //This method logs the user in for the first time after he has registered.
    HttpContext.Current.Response.Redirect("UserPage.aspx", true);
    //After logging in, the user will be redirected to his personal page.
}
第一级:

using System.Web;
在下一步中,请在代码中使用此选项:

 HttpContext.Current.Response.Redirect("UserPage.aspx");

希望帮助你

你需要把@IrishChieftain的帖子作为答案。
 HttpContext.Current.Response.Redirect("UserPage.aspx");