2010-02-16 2 views
3

나는 작업중인 사이트의 로그인 페이지를 긁어 내고 코드를 통해 사용자 이름/암호를 제출하여 사이트에 로그인하려고합니다. 사이트 건강상의 이유로 확인 서비스에서이 작업을 수행하려고합니다. 나는이 메시지를 받고 처리하는 처음있는 몇 가지 문제로 실행하고있어 :화면 긁기에 대한 eventvalidation 오류

Exception information: Exception type: ArgumentException Exception message: Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

나는 eventvalidation을 해제 할 거라고 말할 사이트를 발견했습니다,하지만 난 싶지 않아 보안상의 이유로 그렇게해야합니다. 이 문제를 해결할 방법이 있습니까?

다음은 코드입니다. 기본적으로 내가 바로 여기 K. 스콧 앨런의 기사 떨어져을했다 : http://odetocode.com/Articles/162.aspx

StringBuilder sb = new StringBuilder(); 
     var encryptedConnectionString = GlobalDataObject.EncryptSecure("conn string here", GlobalDataObject.Seed); 
     sb.AppendFormat("client_id={0};", "client"); 
     sb.AppendFormat("client_directory={0};", "client"); 
     sb.AppendFormat("user_id={0};", "12"); 
     sb.AppendFormat("conn_string={0};", encryptedConnectionString); 
     StringBuilder cookiesString = sb; 

     HttpWebRequest webRequest = WebRequest.Create("http://localhost/site/login.aspx?c=client") as HttpWebRequest; 
     webRequest.Headers.Add("Cookie", cookiesString.ToString()); 
     StreamReader responseReader = new StreamReader(
       webRequest.GetResponse().GetResponseStream() 
      ); 
     string responseData = responseReader.ReadToEnd(); 
     responseReader.Close(); 

     // extract the viewstate value and build out POST data 
     string viewState = ExtractViewState(responseData); 
     string postData = string.Format("__VIEWSTATE={0}&Login1$Password={1}&Login1$UserName={2}&Login1$LoginButton={3}", 
                  viewState, 
                HttpUtility.UrlEncode(username), 
                HttpUtility.UrlEncode(password), 
                "Log In"); 

     // have a cookie container ready to receive the forms auth cookie 
     CookieContainer cookies = new CookieContainer(); 

     // now post to the login form 
     webRequest = WebRequest.Create("http://localhost/site/login.aspx") as HttpWebRequest; 
     webRequest.Method = "POST"; 
     webRequest.ContentType = "application/x-www-form-urlencoded"; 
     webRequest.CookieContainer = cookies; 

     // write the form values into the request message 
     StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream()); 
     requestWriter.Write(postData); 
     requestWriter.Close(); 
     webRequest.AuthenticationLevel = AuthenticationLevel.None; 
     // we don't need the contents of the response, just the cookie it issues 
     webRequest.GetResponse().Close(); ///ERROR HAPPENS HERE 

     // now we can send out cookie along with a request for the protected page 
     webRequest = WebRequest.Create("http://localhost/site/user/home.aspx") as HttpWebRequest; 
     webRequest.CookieContainer = cookies; 
     responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream()); 

     // and read the response 
     responseData = responseReader.ReadToEnd(); 
     responseReader.Close(); 

     return responseData; 

감사합니다.

답변

2

이 오류는 앱을 손상시킬 수있는 잘못된 형식의 요청을 찾는 것입니다. 로그인 페이지가되는 것처럼 인코딩되지 않은 HTML 또는 기타를 전달하려고 시도하지 않았을 것입니다.

편집 : 빌드 된 이벤트 유효성 검사 데이터를 캡처하고 viewstate와 같은 로그인 요청으로 다시 보냅니다.

+0

내 코드를 추가했습니다. 나는 어디에서/내가 어떻게 지연을 넣을 지 확신하지 못한다. – gleasonomicon

관련 문제