示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="handler"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static RouteData CreateRouteData(this WindowsLoginHandler handler, Action action)
        {
            RouteData routeData = new RouteData();

            routeData.RouteHandler = new MvcRouteHandler();

            switch (action)
            {
            case Action.Login:
                routeData.Values.Add("controller", controllerName);
                routeData.Values.Add("action", loginActionName);
                break;

            case Action.Link:
                routeData.Values.Add("controller", controllerName);
                routeData.Values.Add("action", linkActionName);
                break;

            case Action.Logoff:
                routeData.Values.Add("controller", controllerName);
                routeData.Values.Add("action", logoffActionName);
                break;

            default:
                throw new NotSupportedException(string.Format("unknonw action value '{0}'.", action));
            }
            return(routeData);
        }
示例#2
0
        /// <summary>
        /// Save a session-state value with the specified userId.
        /// </summary>
        public static void SaveUserIdToSession(this WindowsLoginHandler handler, string userId)
        {
            if (handler.SessionHasUserId())
            {
                throw new ApplicationException("Id already exists in session.");
            }

            handler.Context.Session[userIdKey] = userId;
        }
示例#3
0
        /// <summary>
        /// Saves userId to the items collection inside <see cref="HttpContext"/>.
        /// </summary>
        public static void SaveUserIdToContext(this WindowsLoginHandler handler, string userId)
        {
            if (handler.Context.Items.Contains(userIdKey))
            {
                throw new ApplicationException("Id already exists in context.");
            }

            handler.Context.Items.Add("windows.userId", userId);
        }
示例#4
0
        /// <summary>
        /// Reads userId value from session-state.
        /// </summary>
        /// <remarks>The session-state value removed before this method returns.</remarks>
        /// <param name="session"></param>
        /// <returns></returns>
        public static string ReadUserIdFromSession(this WindowsLoginHandler handler)
        {
            string userId = handler.Context.Session[userIdKey] as string;

            if (string.IsNullOrEmpty(userIdKey))
            {
                throw new ApplicationException("Id not found in session.");
            }

            handler.Context.Session.Remove(userIdKey);

            return(userId);
        }
示例#5
0
 /// <summary>
 /// Returns true if the session contains an entry for userId.
 /// </summary>
 public static bool SessionHasUserId(this WindowsLoginHandler handler)
 {
     return(handler.Context.Session[userIdKey] != null);
 }