Esempio n. 1
0
        internal static string GetWebResourceUrl(Page owner, Type type, string resourceName, bool htmlEncoded, IScriptManager scriptManager)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (string.IsNullOrEmpty(resourceName))
            {
                throw new ArgumentNullException("resourceName");
            }
            if ((owner == null) || !owner.DesignMode)
            {
                return(AssemblyResourceLoader.GetWebResourceUrl(type, resourceName, htmlEncoded, scriptManager));
            }
            ISite site = owner.Site;

            if (site != null)
            {
                IResourceUrlGenerator service = site.GetService(typeof(IResourceUrlGenerator)) as IResourceUrlGenerator;
                if (service != null)
                {
                    return(service.GetResourceUrl(type, resourceName));
                }
            }
            return(resourceName);
        }
Esempio n. 2
0
 private void OnEnter(object source, EventArgs eventArgs)
 {
     if (!_fAuthChecked || _fAuthRequired)
     {
         HttpApplication application = (HttpApplication)source;
         HttpContext     context     = application.Context;
         if (!_fAuthChecked)
         {
             AuthenticationSection authentication = RuntimeConfig.GetAppConfig().Authentication;
             _fAuthRequired = AuthenticationConfig.Mode == AuthenticationMode.Passport;
             _LoginUrl      = authentication.Passport.RedirectUrl;
             _fAuthChecked  = true;
         }
         if (_fAuthRequired)
         {
             PassportIdentity identity = new PassportIdentity();
             this.OnAuthenticate(new PassportAuthenticationEventArgs(identity, context));
             context.SetSkipAuthorizationNoDemand(AuthenticationConfig.AccessingLoginPage(context, _LoginUrl), false);
             if (!context.SkipAuthorization)
             {
                 context.SkipAuthorization = AssemblyResourceLoader.IsValidWebResourceRequest(context);
             }
         }
     }
 }
        ////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////
        // Methods for internal implementation

        /// <internalonly/>
        /// <devdoc>
        /// </devdoc>
        void OnEnter(Object source, EventArgs eventArgs)
        {
            if (_fAuthChecked && !_fAuthRequired)
            {
                return;
            }

            HttpApplication app;
            HttpContext     context;

            app     = (HttpApplication)source;
            context = app.Context;

            if (!_fAuthChecked)
            {
                AuthenticationSection settings = RuntimeConfig.GetAppConfig().Authentication;
                _fAuthRequired = (AuthenticationConfig.Mode == AuthenticationMode.Passport);
                _LoginUrl      = settings.Passport.RedirectUrl;
                _fAuthChecked  = true;
            }

            if (!_fAuthRequired)
            {
                return;
            }

            ////////////////////////////////////////////////////////
            // Step 1: See if this request is valid or not
            // VSWhidbey 442515: We no longer need to do this check, always proceed

            ////////////////////////////////////////////////////////
            // Step 2: Create a Passport Identity from the credentials
            //     from IIS
            PassportIdentity identity = new PassportIdentity();

            ////////////////////////////////////////////////////////
            // Step 4: Call OnAuthenticate virtual method to create
            //    an IPrincipal for this request
            OnAuthenticate(new PassportAuthenticationEventArgs(identity, context));

            ////////////////////////////////////////////////////////
            // Skip AuthZ if accessing the login page
            context.SetSkipAuthorizationNoDemand(AuthenticationConfig.AccessingLoginPage(context, _LoginUrl), false /*managedOnly*/);

            if (!context.SkipAuthorization)
            {
                context.SkipAuthorization = AssemblyResourceLoader.IsValidWebResourceRequest(context);
            }
        }
Esempio n. 4
0
        private void OnEnter(object source, EventArgs eventArgs)
        {
            this._fOnEnterCalled = true;
            HttpApplication application = (HttpApplication)source;
            HttpContext     context     = application.Context;

            this.OnAuthenticate(new FormsAuthenticationEventArgs(context));
            CookielessHelperClass cookielessHelper = context.CookielessHelper;

            if (AuthenticationConfig.AccessingLoginPage(context, FormsAuthentication.LoginUrl))
            {
                context.SetSkipAuthorizationNoDemand(true, false);
                cookielessHelper.RedirectWithDetectionIfRequired(null, FormsAuthentication.CookieMode);
            }
            if (!context.SkipAuthorization)
            {
                context.SetSkipAuthorizationNoDemand(AssemblyResourceLoader.IsValidWebResourceRequest(context), false);
            }
        }
 public ScriptResourceInfo(WebResourceAttribute wra, ScriptResourceAttribute sra, Assembly assembly)
     : this()
 {
     _scriptName            = wra.WebResource;
     _cdnPath               = wra.CdnPath;
     _contentType           = wra.ContentType;
     _performSubstitution   = wra.PerformSubstitution;
     _loadSuccessExpression = wra.LoadSuccessExpression;
     _isDebug               = !String.IsNullOrEmpty(_scriptName) && _scriptName.EndsWith(".debug.js", StringComparison.OrdinalIgnoreCase);
     if (sra != null)
     {
         _scriptResourceName = sra.StringResourceName;
         _typeName           = sra.StringResourceClientTypeName;
     }
     if (!String.IsNullOrEmpty(_cdnPath))
     {
         _cdnPath = AssemblyResourceLoader.FormatCdnUrl(assembly, _cdnPath);
         _cdnPathSecureConnection = AssemblyResourceLoader.FormatCdnUrl(assembly, wra.CdnPathSecureConnection);
     }
 }
        public static void RegisterClientScriptResource(Control control, Type type, string resourceName)
        {
            if (control == null)
            {
                throw new ArgumentNullException("control");
            }
            if (control.Page == null)
            {
                throw new ArgumentException(AtlasWeb.ScriptRegistrationManager_ControlNotOnPage, "control");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (String.IsNullOrEmpty(resourceName))
            {
                throw new ArgumentNullException("resourceName");
            }

            ScriptManager sm = ScriptManager.GetCurrent(control.Page);

            if (sm == null)
            {
                control.Page.ClientScript.RegisterClientScriptResource(type, resourceName);
            }
            else
            {
                Assembly        assembly = AssemblyResourceLoader.GetAssemblyFromType(type);
                ScriptReference script   = new ScriptReference {
                    Name                 = resourceName,
                    Assembly             = assembly.FullName,
                    IsDirectRegistration = true,
                    ClientUrlResolver    = sm
                };
                string resourceUrl = script.GetUrlInternal(sm, sm.Zip);
                control.Page.ClientScript.RegisterClientScriptInclude(type, resourceName, resourceUrl, true);
                RegisteredScript entry = new RegisteredScript(control, type, resourceName, resourceUrl);
                sm.ScriptRegistration.ScriptBlocks.Add(entry);
            }
        }
Esempio n. 7
0
        private static void CopyScriptToStringBuilderWithSubstitution(
            string content, Assembly assembly, bool zip, StringBuilder output)
        {
            // Looking for something of the form: WebResource("resourcename")
            MatchCollection matches    = _webResourceRegEx.Matches(content);
            int             startIndex = 0;

            foreach (Match match in matches)
            {
                output.Append(content.Substring(startIndex, match.Index - startIndex));

                Group  group = match.Groups["resourceName"];
                string embeddedResourceName = group.Value;
                bool   isScriptResource     = String.Equals(
                    match.Groups["resourceType"].Value, "ScriptResource", StringComparison.Ordinal);
                try {
                    if (isScriptResource)
                    {
                        output.Append(ScriptResourceHandler.GetScriptResourceUrl(
                                          assembly, embeddedResourceName, CultureInfo.CurrentUICulture, zip));
                    }
                    else
                    {
                        output.Append(AssemblyResourceLoader.GetWebResourceUrlInternal(
                                          assembly, embeddedResourceName, htmlEncoded: false, forSubstitution: true, scriptManager: null));
                    }
                }
                catch (HttpException e) {
                    throw new HttpException(String.Format(CultureInfo.CurrentCulture,
                                                          AtlasWeb.ScriptResourceHandler_UnknownResource,
                                                          embeddedResourceName), e);
                }

                startIndex = match.Index + match.Length;
            }

            output.Append(content.Substring(startIndex, content.Length - startIndex));
        }
Esempio n. 8
0
        ////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////

        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        private void OnEnter(Object source, EventArgs eventArgs)
        {
            _fOnEnterCalled = true;

            HttpApplication app;
            HttpContext     context;

            app     = (HttpApplication)source;
            context = app.Context;

#if DBG
            Trace("*******************Request path: " + context.Request.RawUrl);
#endif

            ////////////////////////////////////////////////////////
            // Step 2: Call OnAuthenticate virtual method to create
            //    an IPrincipal for this request
            OnAuthenticate(new FormsAuthenticationEventArgs(context));

            ////////////////////////////////////////////////////////
            // Skip AuthZ if accessing the login page

            // We do this here to force the cookieless helper to fish out and
            // remove the token from the URL if it's present there.
            CookielessHelperClass cookielessHelper = context.CookielessHelper;

            if (AuthenticationConfig.AccessingLoginPage(context, FormsAuthentication.LoginUrl))
            {
                context.SetSkipAuthorizationNoDemand(true, false /*managedOnly*/);
                cookielessHelper.RedirectWithDetectionIfRequired(null, FormsAuthentication.CookieMode);
            }
            if (!context.SkipAuthorization)
            {
                context.SetSkipAuthorizationNoDemand(AssemblyResourceLoader.IsValidWebResourceRequest(context), false /*managedOnly*/);
            }
        }
Esempio n. 9
0
        internal void RenderWebFormsScript(HtmlTextWriter writer)
        {
            Dictionary <string, object> dictionary;

            if (((this._registeredResourcesToSuppress == null) || !this._registeredResourcesToSuppress.TryGetValue(AssemblyResourceLoader.GetAssemblyFromType(typeof(Page)), out dictionary)) || !dictionary.ContainsKey("WebForms.js"))
            {
                writer.Write("\r\n<script src=\"");
                writer.Write(GetWebResourceUrl(this._owner, typeof(Page), "WebForms.js", true, this._owner.ScriptManager));
                writer.WriteLine("\" type=\"text/javascript\"></script>");
            }
        }