2013-10-26 2 views
6

asp.net을 사용하여 웹 응용 프로그램을 코딩하는 중입니다. 사용자는 자격 증명을 입력하고 인증을 위해 실제 전자 메일 주소와 암호에 대해 유효성을 검사합니다. 이 데이터를 처리하기위한 클래스를 별도의 .cs 파일로 작성했습니다.내 custom 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"); 

희망이 당신에게 당신이 필요로하는

관련 문제