2013-10-26 6 views
6

私はasp.netでWebアプリケーションをコーディングする過程にあります。ユーザーは資格情報を入力し、これらは認証のために実際の電子メールアドレスとパスワードに対して検証されます。私は、これらのデータを処理するためのいくつかのクラスを別々の.csファイルで作成しました。私のカスタムC#クラスからresponse.redirectを呼び出す方法

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

} 

しかし、私は別々のCSファイル内にあるログインクラス内からのResponse.Redirect()メソッドにアクセスすることができないように思われます。 (私はaspxページのために書いたイベントハンドラの中からアクセスできます)誰にもアイデアはありますか?手伝ってくれてありがとう!

+1

役立ちます答えとして@ IrishChieftainの投稿をマークする。 –

答えて

1

はい、あなたはこのように、それに対する応答を渡ししたいと思うので、そこにあなたの方法は、(それが静的でなかった場合には、コードビハインドで動作します)静的であるため、:

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

大会のためにレスポンスは「レスポンス」に変更する必要があります。

17

は、完全な名前空間を使用してみてください:

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

それは働いた。どうもありがとう。 –

+1

答えとしてマークすることを忘れないでください:-) – IrishChieftain

0

最初のレベル:あなたのコード内の次の使用中

using System.Web; 

この:

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

希望は、あなたが必要

関連する問題