2011-04-20 6 views
0

외부에서 인증하기 위해 ASP.Net MVC 끝점을 만들려고합니다. 아이디어는 콘솔 응용 프로그램, WPF 응용 프로그램 또는 기타에서 끝점을 호출하고 JSON을 인증 된 사용자에게 반환하고 특성을 통해 인증을 확인하는 등 내 서비스에 MVC 패턴을 사용할 수 있도록하기위한 것입니다. 콘솔 응용 프로그램을 사용하고 있습니다. 이제는 빠르고 간단하기 때문입니다.콘솔 응용 프로그램의 ASP.Net MVC 쿠키

나는 지금까지이 : 내 콘솔 응용 프로그램에서

: 나는 콘솔 응용 프로그램에서 응답을 검사 할 때

<HttpPost()> 
Public Function LogIn(model As LogOnModel) As ActionResult 
    If ModelState.IsValid Then 
     If Membership.ValidateUser(model.UserName, model.Password) Then 
      Dim cookie As HttpCookie = FormsAuthentication.GetAuthCookie(model.UserName, False) 
      cookie.Expires = DateTime.Now.AddMinutes(20) 
      Request.Cookies.Add(cookie) 
      Request.Cookies.Add(New HttpCookie("Barney", "Rubble")) 

      Return Content("Logged In Ok") 
     Else 
      Return New HttpUnauthorizedResult 
     End If 
    Else 
     Return New HttpUnauthorizedResult 
    End If 
End Function 

지금, 거기에 내 컨트롤러에서

Public Sub MakeLoginRequest() 
     Dim address As Uri = New Uri("http://localhost:50536/Account/LogIn") 
     Dim request As HttpWebRequest = HttpWebRequest.Create(address) 
     request.Method = "POST" 
     request.ContentType = "application/json; charset=utf-8" 

     Dim loginModel As New LogOnModel With {.UserName = "Richard", 
               .Password = "Password1", 
               .RememberMe = False} 

     Dim jsonData As String = JsonConvert.SerializeObject(loginModel) 
     Dim bytes As Byte() = System.Text.Encoding.ASCII.GetBytes(jsonData) 
     request.GetRequestStream.Write(bytes, 0, bytes.Count) 

     Dim response As HttpWebResponse = request.GetResponse() 
End Sub 

어떤 쿠키도 절대 사용하지 마십시오. 실제 인증 쿠키 나 위조 된 바니 루블 쿠키가 실제로 나타나지 않습니다!

그러나 ... Chrome에서 동일한 전화를 걸고 응답을 확인 ... 두 쿠키가 있습니다!

누구에게 무슨 문제가 있습니까? 여기에 설명 된대로

답변

관련 문제