示例#1
0
        private void OnLeave(object source, EventArgs eventArgs)
        {
            HttpApplication application = (HttpApplication)source;
            HttpContext     context     = application.Context;

            if ((_fAuthChecked && _fAuthRequired) && (((context.User != null) && (context.User.Identity != null)) && (context.User.Identity is PassportIdentity)))
            {
                PassportIdentity identity = (PassportIdentity)context.User.Identity;
                if ((context.Response.StatusCode == 0x191) && !identity.WWWAuthHeaderSet)
                {
                    if (((_LoginUrl == null) || (_LoginUrl.Length < 1)) || (string.Compare(_LoginUrl, "internal", StringComparison.Ordinal) == 0))
                    {
                        context.Response.Clear();
                        context.Response.StatusCode = 200;
                        if (!ErrorFormatter.RequiresAdaptiveErrorReporting(context))
                        {
                            string str   = context.Request.Url.ToString();
                            int    index = str.IndexOf('?');
                            if (index >= 0)
                            {
                                str = str.Substring(0, index);
                            }
                            string str2 = identity.LogoTag2(HttpUtility.UrlEncode(str, context.Request.ContentEncoding));
                            string s    = System.Web.SR.GetString("PassportAuthFailed", new object[] { str2 });
                            context.Response.Write(s);
                        }
                        else
                        {
                            ErrorFormatter formatter = new PassportAuthFailedErrorFormatter();
                            context.Response.Write(formatter.GetAdaptiveErrorMessage(context, true));
                        }
                    }
                    else
                    {
                        string str7;
                        string completeLoginUrl = AuthenticationConfig.GetCompleteLoginUrl(context, _LoginUrl);
                        if ((completeLoginUrl == null) || (completeLoginUrl.Length <= 0))
                        {
                            throw new HttpException(System.Web.SR.GetString("Invalid_Passport_Redirect_URL"));
                        }
                        string str5 = context.Request.Url.ToString();
                        if (completeLoginUrl.IndexOf('?') >= 0)
                        {
                            str7 = "&";
                        }
                        else
                        {
                            str7 = "?";
                        }
                        string url  = completeLoginUrl + str7 + "ReturnUrl=" + HttpUtility.UrlEncode(str5, context.Request.ContentEncoding);
                        int    num2 = str5.IndexOf('?');
                        if ((num2 >= 0) && (num2 < (str5.Length - 1)))
                        {
                            url = url + "&" + str5.Substring(num2 + 1);
                        }
                        context.Response.Redirect(url, false);
                    }
                }
            }
        }
        void OnLeave(Object source, EventArgs eventArgs) {
            HttpApplication app;
            HttpContext context;
            app = (HttpApplication)source;
            context = app.Context;
            if (!_fAuthChecked || !_fAuthRequired || context.User == null || context.User.Identity == null || !(context.User.Identity is PassportIdentity))
                return;



            PassportIdentity id = (PassportIdentity) context.User.Identity;
            if (context.Response.StatusCode != 401 || id.WWWAuthHeaderSet)
                return;

            if ( _LoginUrl==null || _LoginUrl.Length < 1 || String.Compare(_LoginUrl, "internal", StringComparison.Ordinal) == 0) {
                context.Response.Clear();
                context.Response.StatusCode = 200;

                if (!ErrorFormatter.RequiresAdaptiveErrorReporting(context)) {
                    String strUrl = context.Request.Url.ToString();
                    int iPos = strUrl.IndexOf('?');
                    if (iPos >= 0) {
                        strUrl = strUrl.Substring(0, iPos);
                    }
                    String strLogoTag = id.LogoTag2(HttpUtility.UrlEncode(strUrl, context.Request.ContentEncoding));

                    String strMsg = SR.GetString(SR.PassportAuthFailed, strLogoTag);
                    context.Response.Write(strMsg);
                }
                else {
                    ErrorFormatter errorFormatter = new PassportAuthFailedErrorFormatter();
                    context.Response.Write(errorFormatter.GetAdaptiveErrorMessage(context, true));
                }
            }
            else {
                ////////////////////////////////////////////////////////////
                // Step 1: Get the redirect url
                String redirectUrl = AuthenticationConfig.GetCompleteLoginUrl(context, _LoginUrl);
                
                ////////////////////////////////////////////////////////////
                // Step 2: Check if we have a valid url to the redirect-page
                if (redirectUrl == null || redirectUrl.Length <= 0) 
                    throw new HttpException(SR.GetString(SR.Invalid_Passport_Redirect_URL));

                
                ////////////////////////////////////////////////////////////
                // Step 3: Construct the redirect-to url
                String             strUrl       = context.Request.Url.ToString();
                String             strRedirect;
                int                iIndex;
                String             strSep;
            
                if (redirectUrl.IndexOf('?') >= 0)
                    strSep = "&";
                else
                    strSep = "?";
                
                strRedirect = redirectUrl  + strSep + "ReturnUrl=" + HttpUtility.UrlEncode(strUrl, context.Request.ContentEncoding);
                

                ////////////////////////////////////////////////////////////
                // Step 4: Add the query-string from the current url
                iIndex = strUrl.IndexOf('?');
                if (iIndex >= 0 && iIndex < strUrl.Length-1)
                    strRedirect += "&" + strUrl.Substring(iIndex+1);
                

                ////////////////////////////////////////////////////////////
                // Step 5: Do the redirect
                context.Response.Redirect(strRedirect, false);
            }
        }
 private void OnLeave(object source, EventArgs eventArgs)
 {
     HttpApplication application = (HttpApplication) source;
     HttpContext context = application.Context;
     if ((_fAuthChecked && _fAuthRequired) && (((context.User != null) && (context.User.Identity != null)) && (context.User.Identity is PassportIdentity)))
     {
         PassportIdentity identity = (PassportIdentity) context.User.Identity;
         if ((context.Response.StatusCode == 0x191) && !identity.WWWAuthHeaderSet)
         {
             if (((_LoginUrl == null) || (_LoginUrl.Length < 1)) || (string.Compare(_LoginUrl, "internal", StringComparison.Ordinal) == 0))
             {
                 context.Response.Clear();
                 context.Response.StatusCode = 200;
                 if (!ErrorFormatter.RequiresAdaptiveErrorReporting(context))
                 {
                     string str = context.Request.Url.ToString();
                     int index = str.IndexOf('?');
                     if (index >= 0)
                     {
                         str = str.Substring(0, index);
                     }
                     string str2 = identity.LogoTag2(HttpUtility.UrlEncode(str, context.Request.ContentEncoding));
                     string s = System.Web.SR.GetString("PassportAuthFailed", new object[] { str2 });
                     context.Response.Write(s);
                 }
                 else
                 {
                     ErrorFormatter formatter = new PassportAuthFailedErrorFormatter();
                     context.Response.Write(formatter.GetAdaptiveErrorMessage(context, true));
                 }
             }
             else
             {
                 string str7;
                 string completeLoginUrl = AuthenticationConfig.GetCompleteLoginUrl(context, _LoginUrl);
                 if ((completeLoginUrl == null) || (completeLoginUrl.Length <= 0))
                 {
                     throw new HttpException(System.Web.SR.GetString("Invalid_Passport_Redirect_URL"));
                 }
                 string str5 = context.Request.Url.ToString();
                 if (completeLoginUrl.IndexOf('?') >= 0)
                 {
                     str7 = "&";
                 }
                 else
                 {
                     str7 = "?";
                 }
                 string url = completeLoginUrl + str7 + "ReturnUrl=" + HttpUtility.UrlEncode(str5, context.Request.ContentEncoding);
                 int num2 = str5.IndexOf('?');
                 if ((num2 >= 0) && (num2 < (str5.Length - 1)))
                 {
                     url = url + "&" + str5.Substring(num2 + 1);
                 }
                 context.Response.Redirect(url, false);
             }
         }
     }
 }
        void OnLeave(Object source, EventArgs eventArgs)
        {
            HttpApplication app;
            HttpContext     context;

            app     = (HttpApplication)source;
            context = app.Context;
            if (!_fAuthChecked || !_fAuthRequired || context.User == null || context.User.Identity == null || !(context.User.Identity is PassportIdentity))
            {
                return;
            }



            PassportIdentity id = (PassportIdentity)context.User.Identity;

            if (context.Response.StatusCode != 401 || id.WWWAuthHeaderSet)
            {
                return;
            }

            if (_LoginUrl == null || _LoginUrl.Length < 1 || String.Compare(_LoginUrl, "internal", StringComparison.Ordinal) == 0)
            {
                context.Response.Clear();
                context.Response.StatusCode = 200;

                if (!ErrorFormatter.RequiresAdaptiveErrorReporting(context))
                {
                    String strUrl = context.Request.Url.ToString();
                    int    iPos   = strUrl.IndexOf('?');
                    if (iPos >= 0)
                    {
                        strUrl = strUrl.Substring(0, iPos);
                    }
                    String strLogoTag = id.LogoTag2(HttpUtility.UrlEncode(strUrl, context.Request.ContentEncoding));

                    String strMsg = SR.GetString(SR.PassportAuthFailed, strLogoTag);
                    context.Response.Write(strMsg);
                }
                else
                {
                    ErrorFormatter errorFormatter = new PassportAuthFailedErrorFormatter();
                    context.Response.Write(errorFormatter.GetAdaptiveErrorMessage(context, true));
                }
            }
            else
            {
                ////////////////////////////////////////////////////////////
                // Step 1: Get the redirect url
                String redirectUrl = AuthenticationConfig.GetCompleteLoginUrl(context, _LoginUrl);

                ////////////////////////////////////////////////////////////
                // Step 2: Check if we have a valid url to the redirect-page
                if (redirectUrl == null || redirectUrl.Length <= 0)
                {
                    throw new HttpException(SR.GetString(SR.Invalid_Passport_Redirect_URL));
                }


                ////////////////////////////////////////////////////////////
                // Step 3: Construct the redirect-to url
                String strUrl = context.Request.Url.ToString();
                String strRedirect;
                int    iIndex;
                String strSep;

                if (redirectUrl.IndexOf('?') >= 0)
                {
                    strSep = "&";
                }
                else
                {
                    strSep = "?";
                }

                strRedirect = redirectUrl + strSep + "ReturnUrl=" + HttpUtility.UrlEncode(strUrl, context.Request.ContentEncoding);


                ////////////////////////////////////////////////////////////
                // Step 4: Add the query-string from the current url
                iIndex = strUrl.IndexOf('?');
                if (iIndex >= 0 && iIndex < strUrl.Length - 1)
                {
                    strRedirect += "&" + strUrl.Substring(iIndex + 1);
                }


                ////////////////////////////////////////////////////////////
                // Step 5: Do the redirect
                context.Response.Redirect(strRedirect, false);
            }
        }