2016-07-06 1 views
0

를 반환하지 않습니다. 경우에 따라 UserId을 반환하고 다른 경우에는 -1을 반환합니다. 로그인 페이지가 있으므로 응용 프로그램에 로그인 한 사용자의 UserId을 가져와야합니다.WebSecurity.GetUserID은 (HttpContext.Current.User.Identity.Name)는 항상 내가 <code>WebMatrix</code> 응용 프로그램이 있고 나는 <code>UserID</code>을 잡아 <code>WebSecurity.GetUserId(Http.Current.User.Identity.Name)</code>을 사용하고있는 사용자 ID

var UserId = WebSecurity.GetUserId(HttpContext.Current.User.Identity.Name); 
    var User = WebSecurity.CurrentUserName; 
    var UserEmail = WebSecurity.CurrentUserName; 
    var dbApp = Database.Open("ApplicationServices"); 
    var selectUser = "SELECT UserId, UserName, Location FROM LocationTable, UserTable WHERE (UserId) = (@0) AND (UserLocation) = (Id)"; 
    var person = dbApp.QuerySingle(selectUser, UserId); 

왜 일치하지 않습니다 : 여기에

내 코드?

답변

1

사용자 (또는 사용자)가 단지 session timeout (즉, WebSecurity.CurrentUserId = -1)을 경험하고 있으며,이 경우 사용자가 시간 초과가 된 후에 사용자를 다시 로그인 페이지로 리디렉션하려는 경우가 있습니다. 시간 초과 값을 결정/설정하고 필요에 따라 테스트하려면 양식 인증, Windows 인증 또는 (ick) 서버 세션을 사용하는지 확인해야합니다.

사용자에게 가장 좋은 점은 AuthorizeAttribute/AuthorizeCore을 사용하고 HandleUnauthorizedRequest 메서드를 사용하여 세션 만료시 로그인 페이지로 다시 리디렉션하는 것입니다.

+0

샘플 코드가 있습니까? – tnbumbray

+0

[여기에 좋은 샘플] (http://stackoverflow.com/a/13292334/6415885) – SqlOnly

관련 문제