2013-10-26 20 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"); 

希望可以幫助您

相關問題