Exemplo n.º 1
0
        void Application_BeginRequest(object sender, EventArgs e)
        {
            string securableName = GetSecurableNameForCurrentRequestPath();

            if (String.IsNullOrEmpty(securableName))
            {
                return;
            }

            ISecurable relevantSecurable = Placeholder.GetSecurable(securableName);

            if (relevantSecurable == null)
            {
                return;
            }

            if (relevantSecurable.AllowAnonymous)
            {
                return;
            }

            if (!ConnectGadgetCache.IsAuthenticated)
            {
                // Redirect to the login page with the current URL as the return URL
                Response.Redirect(LOGIN_PAGE_URL + "?ReturnUrl=" + HttpUtility.UrlEncode(Request.Url.ToString()), true);
            }

            if (!relevantSecurable.IsAuthorized(ConnectGadgetCache.CurrentUser))
            {
                throw (new UnauthorizedAccessException("You do not have access to this resource"));
            }
        }