How to call response.redirect from my custom C # class

I am coding a web application using asp.net. Users enter their credentials, and they are checked on the actual email address and password for authorization. I wrote several classes to process this data (in a separate .cs file).

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

However, I seem to be unable to access the Response.Redirect () method from the Login class, which is in a separate cs file. (I can access it from the event handlers that I wrote for the aspx page.) Does anyone have an idea? Thank you in advance for your help!

+6
source share
3 answers

Try using the full namespace:

 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. } 
+17
source

Yes, because your method has a static one (it would work in the code if it weren't static), so you want to pass an answer to it, for example:

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

for agreement, the Response must be changed to โ€œresponseโ€.

+1
source

first level:

 using System.Web; 

in the following use this in your code:

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

Hope will help you

0
source

Source: https://habr.com/ru/post/956803/


All Articles