Тайм-аут аутентификации форм по сравнению с тайм-аутом сессии

Можно использовать #send метод для называния метода объекта именем метода:

object.send(:foo) # same as object.foo

можно передать споры с вызываемому методу:

object.send(:foo, 1, "bar", 1.23) # same as object.foo(1, "bar", 1.23)

Так, если у Вас есть название атрибута в переменном "атрибуте", можно считать атрибут объекта с [1 110]

object.send(attribute.to_sym)

и записать значение атрибута с [1 111]

object.send("#{attribute}=".to_sym, value)

В Ruby, 1.8.6 #send методов могут выполнить метод любого объекта независимо от своей видимости (Вы можете, например, называть закрытые методы). Это подвержено изменениям в будущих версиях Ruby, и Вы не должны полагаться на него. Для выполнения закрытых методов используйте #instance_eval:

object.instance_eval {
  # code as block, can reference variables in current scope
}

# or

object.instance_eval <<-CODE
  # code as string, can generate any code text
CODE

Обновление

можно использовать public_send для вызова методов относительно правил видимости.

object.public_send :public_foo # ok
object.public_send :private_bar # exception
59
задан GaTechThomas 22 December 2014 в 22:36
поделиться

1 ответ

  1. To be on the safe side: TimeOut(Session) <= TimeOut(FormsAuthentication) * 2
  2. If you want to show page other than specified in loginUrl attribute after authentication timeout you need to handle this manually as ASP.NET does not provide a way of doing it.

To achieve #2 you can manually check the cookie and its AuthenticationTicket for expiration and redirect to your custom page if they have expired.
You can do in it in one of the events: AcquireRequestState, AuthenticateRequest.

Sample code in the event can look like:

// Retrieve AuthenticationCookie
var cookie = Request.Cookies[FormsAuthentication.FormsCookieName];
if (cookie == null) return;
FormsAuthenticationTicket ticket = null;
try {
    ticket = FormsAuthentication.Decrypt(cookie.Value);
} catch (Exception decryptError) {
    // Handle properly
}
if (ticket == null) return; // Not authorised
if (ticket.Expiration > DateTime.Now) {
    Response.Redirect("SessionExpiredPage.aspx"); // Or do other stuff here
}
50
ответ дан 24 November 2019 в 18:31
поделиться
Другие вопросы по тегам:

Похожие вопросы: