12

I am in the process of coding a web application with asp.net. The users enter their credentials and these are validated against the actual email address and password for authorization. I wrote some classes for processing these data (in a seperate .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 not to be able to access the Response.Redirect() method from inside the Login class which is in the seperate cs file. (I can access it from inside the event handlers I wrote for the aspx page.) Does anyone have an idea? Thank you in advance for helping!

1

3 Answers 3

26

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.
}
0
2

first level :

using System.Web;

in next use this in your code :

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

hope helps you

1

Yes, because your method there is static (it would work in the code-behind if it wasn't static), so you'll want to pass response to it, like this:

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

for convention Response should be changed to 'response'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.