internal void LoadValuesFromConfigurationXml(XmlNode node)
        {
            // DO NOT SILENTLY IGNORE BOGUS XML IN THE SECTION!
            HandlerBase.CheckForChildNodes(node);

            foreach (XmlAttribute attribute in node.Attributes)
            {
                String name = attribute.Name;
                String text = attribute.Value;

                try {
                    if (name == "culture")
                    {
                        if (text.Length == 0)
                        {
                            throw new ArgumentException();  // don't allow empty culture string
                        }
                        _culture = HttpServerUtility.CreateReadOnlyCultureInfo(text);
                    }
                    else if (name == "uiCulture")
                    {
                        if (text.Length == 0)
                        {
                            throw new ArgumentException();  // don't allow empty culture string
                        }
                        _uiCulture = HttpServerUtility.CreateReadOnlyCultureInfo(text);
                    }
                    else if (name == "fileEncoding")
                    {
                        _fileEncoding = Encoding.GetEncoding(text);
                    }
                    else if (name == "requestEncoding")
                    {
                        _requestEncoding = Encoding.GetEncoding(text);
                    }
                    else if (name == "responseEncoding")
                    {
                        _responseEncoding = Encoding.GetEncoding(text);
                    }
                    else
                    {
                        throw new ConfigurationException(
                                  HttpRuntime.FormatResourceString(SR.Unknown_globalization_attr, name),
                                  attribute);
                    }
                }
                catch (ConfigurationException) {
                    throw;
                }
                catch (Exception e) {
                    throw new ConfigurationException(
                              HttpRuntime.FormatResourceString(SR.Invalid_value_for_globalization_attr, name),
                              e, attribute);
                }
            }
        }
 // Given a single culture name, attempts to turn it into a CultureInfo.
 // If 'requireSpecific' is set, this method attempts to return an object where IsNeutral = false.
 public static CultureInfo CreateReadOnlyCulture(string cultureName, bool requireSpecific)
 {
     if (requireSpecific)
     {
         return(HttpServerUtility.CreateReadOnlySpecificCultureInfo(cultureName));
     }
     else
     {
         return(HttpServerUtility.CreateReadOnlyCultureInfo(cultureName));
     }
 }
Esempio n. 3
0
        internal static bool IsCultureName(string s)
        {
            if (string.IsNullOrEmpty(s))
            {
                return(false);
            }
            foreach (string str in s_invalidCultureNames)
            {
                if (StringUtil.EqualsIgnoreCase(str, s))
                {
                    return(false);
                }
            }
            CultureInfo info = null;

            try
            {
                info = HttpServerUtility.CreateReadOnlyCultureInfo(s);
            }
            catch
            {
            }
            return(info != null);
        }
        internal override bool ProcessMainDirectiveAttribute(string deviceName, string name, string value, IDictionary parseData)
        {
            switch (name)
            {
            case "errorpage":
                this._errorPage = System.Web.UI.Util.GetNonEmptyAttribute(name, value);
                return(false);

            case "contenttype":
                System.Web.UI.Util.GetNonEmptyAttribute(name, value);
                return(false);

            case "theme":
                if (!base.IsExpressionBuilderValue(value))
                {
                    System.Web.UI.Util.CheckThemeAttribute(value);
                    return(false);
                }
                return(false);

            case "stylesheettheme":
                base.ValidateBuiltInAttribute(deviceName, name, value);
                System.Web.UI.Util.CheckThemeAttribute(value);
                this._styleSheetTheme = value;
                return(true);

            case "enablesessionstate":
                this.flags[0x100000] = true;
                this.flags[0x200000] = false;
                if (!System.Web.UI.Util.IsFalseString(value))
                {
                    if (StringUtil.EqualsIgnoreCase(value, "readonly"))
                    {
                        this.flags[0x200000] = true;
                    }
                    else if (!System.Web.UI.Util.IsTrueString(value))
                    {
                        base.ProcessError(System.Web.SR.GetString("Enablesessionstate_must_be_true_false_or_readonly"));
                    }
                    break;
                }
                this.flags[0x100000] = false;
                break;

            case "culture":
                this._culture = System.Web.UI.Util.GetNonEmptyAttribute(name, value);
                if (!HttpRuntime.HasAspNetHostingPermission(AspNetHostingPermissionLevel.Medium))
                {
                    throw new HttpException(System.Web.SR.GetString("Insufficient_trust_for_attribute", new object[] { "culture" }));
                }
                if (!StringUtil.EqualsIgnoreCase(value, HttpApplication.AutoCulture))
                {
                    CultureInfo info;
                    try
                    {
                        if (StringUtil.StringStartsWithIgnoreCase(value, HttpApplication.AutoCulture))
                        {
                            this._culture = this._culture.Substring(5);
                        }
                        info = HttpServerUtility.CreateReadOnlyCultureInfo(this._culture);
                    }
                    catch
                    {
                        base.ProcessError(System.Web.SR.GetString("Invalid_attribute_value", new object[] { this._culture, "culture" }));
                        return(false);
                    }
                    if (info.IsNeutralCulture)
                    {
                        base.ProcessError(System.Web.SR.GetString("Invalid_culture_attribute", new object[] { System.Web.UI.Util.GetSpecificCulturesFormattedList(info) }));
                    }
                }
                return(false);

            case "lcid":
                if (!base.IsExpressionBuilderValue(value))
                {
                    this._lcid = System.Web.UI.Util.GetNonNegativeIntegerAttribute(name, value);
                    try
                    {
                        HttpServerUtility.CreateReadOnlyCultureInfo(this._lcid);
                    }
                    catch
                    {
                        base.ProcessError(System.Web.SR.GetString("Invalid_attribute_value", new object[] { this._lcid.ToString(CultureInfo.InvariantCulture), "lcid" }));
                    }
                    return(false);
                }
                return(false);

            case "uiculture":
                System.Web.UI.Util.GetNonEmptyAttribute(name, value);
                return(false);

            case "responseencoding":
                if (!base.IsExpressionBuilderValue(value))
                {
                    this._responseEncoding = System.Web.UI.Util.GetNonEmptyAttribute(name, value);
                    Encoding.GetEncoding(this._responseEncoding);
                    return(false);
                }
                return(false);

            case "codepage":
                if (!base.IsExpressionBuilderValue(value))
                {
                    this._codePage = System.Web.UI.Util.GetNonNegativeIntegerAttribute(name, value);
                    Encoding.GetEncoding(this._codePage);
                    return(false);
                }
                return(false);

            case "transaction":
                base.OnFoundAttributeRequiringCompilation(name);
                this.ParseTransactionAttribute(name, value);
                goto Label_05CF;

            case "aspcompat":
                base.OnFoundAttributeRequiringCompilation(name);
                this.flags[0x40] = System.Web.UI.Util.GetBooleanAttribute(name, value);
                if (this.flags[0x40] && !HttpRuntime.HasUnmanagedPermission())
                {
                    throw new HttpException(System.Web.SR.GetString("Insufficient_trust_for_attribute", new object[] { "AspCompat" }));
                }
                goto Label_05CF;

            case "async":
                base.OnFoundAttributeRequiringCompilation(name);
                this.flags[0x800000] = System.Web.UI.Util.GetBooleanAttribute(name, value);
                if (!HttpRuntime.HasAspNetHostingPermission(AspNetHostingPermissionLevel.Medium))
                {
                    throw new HttpException(System.Web.SR.GetString("Insufficient_trust_for_attribute", new object[] { "async" }));
                }
                goto Label_05CF;

            case "tracemode":
            {
                object obj2 = System.Web.UI.Util.GetEnumAttribute(name, value, typeof(TraceModeInternal));
                this._traceMode = (System.Web.TraceMode)obj2;
                goto Label_05CF;
            }

            case "trace":
                if (!System.Web.UI.Util.GetBooleanAttribute(name, value))
                {
                    this._traceEnabled = TraceEnable.Disable;
                }
                else
                {
                    this._traceEnabled = TraceEnable.Enable;
                }
                goto Label_05CF;

            case "smartnavigation":
                base.ValidateBuiltInAttribute(deviceName, name, value);
                return(!System.Web.UI.Util.GetBooleanAttribute(name, value));

            case "maintainscrollpositiononpostback":
                return(!System.Web.UI.Util.GetBooleanAttribute(name, value));

            case "validaterequest":
                this.flags[0x400000] = System.Web.UI.Util.GetBooleanAttribute(name, value);
                goto Label_05CF;

            case "clienttarget":
                if (!base.IsExpressionBuilderValue(value))
                {
                    HttpCapabilitiesDefaultProvider.GetUserAgentFromClientTarget(base.CurrentVirtualPath, value);
                    return(false);
                }
                return(false);

            case "masterpagefile":
                if (!base.IsExpressionBuilderValue(value))
                {
                    if (value.Length > 0)
                    {
                        Type referencedType = base.GetReferencedType(value);
                        if (!typeof(MasterPage).IsAssignableFrom(referencedType))
                        {
                            base.ProcessError(System.Web.SR.GetString("Invalid_master_base", new object[] { value }));
                        }
                        if (deviceName.Length > 0)
                        {
                            this.EnsureMasterPageFileFromConfigApplied();
                        }
                    }
                    this._mainDirectiveMasterPageSet = true;
                    return(false);
                }
                return(false);

            default:
                return(base.ProcessMainDirectiveAttribute(deviceName, name, value, parseData));
            }
            if (this.flags[0x100000])
            {
                base.OnFoundAttributeRequiringCompilation(name);
            }
Label_05CF:
            base.ValidateBuiltInAttribute(deviceName, name, value);
            return(true);
        }
Esempio n. 5
0
        internal override bool ProcessMainDirectiveAttribute(string deviceName, string name,
                                                             string value, IDictionary parseData)
        {
            switch (name)
            {
            case "errorpage":
                _errorPage = Util.GetNonEmptyAttribute(name, value);

                // Return false to let the generic attribute processing continue
                return(false);

            case "contenttype":
                // Check validity
                Util.GetNonEmptyAttribute(name, value);

                // Return false to let the generic attribute processing continue
                return(false);

            case "theme":
                if (IsExpressionBuilderValue(value))
                {
                    return(false);
                }

                // Check validity
                Util.CheckThemeAttribute(value);

                // Return false to let the generic attribute processing continue
                return(false);

            case "stylesheettheme":
                // Make sure no device filter or expression builder was specified
                ValidateBuiltInAttribute(deviceName, name, value);

                // Check validity
                Util.CheckThemeAttribute(value);

                _styleSheetTheme = value;
                return(true);

            case "enablesessionstate":
                flags[requiresSessionState] = true;
                flags[readOnlySessionState] = false;
                if (Util.IsFalseString(value))
                {
                    flags[requiresSessionState] = false;
                }
                else if (StringUtil.EqualsIgnoreCase(value, "readonly"))
                {
                    flags[readOnlySessionState] = true;
                }
                else if (!Util.IsTrueString(value))
                {
                    ProcessError(SR.GetString(SR.Enablesessionstate_must_be_true_false_or_readonly));
                }

                if (flags[requiresSessionState])
                {
                    // Session state is only available for compiled pages
                    OnFoundAttributeRequiringCompilation(name);
                }
                break;

            case "culture":
                _culture = Util.GetNonEmptyAttribute(name, value);

                // Setting culture requires medium permission
                if (!HttpRuntime.HasAspNetHostingPermission(AspNetHostingPermissionLevel.Medium))
                {
                    throw new HttpException(SR.GetString(SR.Insufficient_trust_for_attribute, "culture"));
                }

                //do not verify at parse time if potentially using browser AutoDetect
                if (StringUtil.EqualsIgnoreCase(value, HttpApplication.AutoCulture))
                {
                    return(false);
                }


                // Create a CultureInfo just to verify validity
                CultureInfo cultureInfo;

                try {
                    if (StringUtil.StringStartsWithIgnoreCase(value, HttpApplication.AutoCulture))
                    {
                        //safe to trim leading "auto:", string used elsewhere for null check
                        _culture = _culture.Substring(5);
                    }
                    cultureInfo = HttpServerUtility.CreateReadOnlyCultureInfo(_culture);
                }
                catch {
                    ProcessError(SR.GetString(SR.Invalid_attribute_value, _culture, "culture"));
                    return(false);
                }

                // Don't allow neutral cultures (ASURT 77930)
                if (cultureInfo.IsNeutralCulture)
                {
                    ProcessError(SR.GetString(SR.Invalid_culture_attribute,
                                              Util.GetSpecificCulturesFormattedList(cultureInfo)));
                }

                // Return false to let the generic attribute processing continue
                return(false);

            case "lcid":
                // Skip validity check for expression builder (e.g. <%$ ... %>)
                if (IsExpressionBuilderValue(value))
                {
                    return(false);
                }

                _lcid = Util.GetNonNegativeIntegerAttribute(name, value);

                // Create a CultureInfo just to verify validity
                try {
                    HttpServerUtility.CreateReadOnlyCultureInfo(_lcid);
                }
                catch {
                    ProcessError(SR.GetString(SR.Invalid_attribute_value,
                                              _lcid.ToString(CultureInfo.InvariantCulture), "lcid"));
                }

                // Return false to let the generic attribute processing continue
                return(false);

            case "uiculture":
                // Check validity
                Util.GetNonEmptyAttribute(name, value);

                // Return false to let the generic attribute processing continue
                return(false);

            case "responseencoding":
                // Skip validity check for expression builder (e.g. <%$ ... %>)
                if (IsExpressionBuilderValue(value))
                {
                    return(false);
                }

                _responseEncoding = Util.GetNonEmptyAttribute(name, value);

                // Call Encoding.GetEncoding just to verify validity
                Encoding.GetEncoding(_responseEncoding);

                // Return false to let the generic attribute processing continue
                return(false);

            case "codepage":
                // Skip validity check for expression builder (e.g. <%$ ... %>)
                if (IsExpressionBuilderValue(value))
                {
                    return(false);
                }

                _codePage = Util.GetNonNegativeIntegerAttribute(name, value);

                // Call Encoding.GetEncoding just to verify validity
                Encoding.GetEncoding(_codePage);

                // Return false to let the generic attribute processing continue
                return(false);

            case "transaction":
                // This only makes sense for compiled pages
                OnFoundAttributeRequiringCompilation(name);

                ParseTransactionAttribute(name, value);
                break;

            case "aspcompat":
                // This only makes sense for compiled pages
                OnFoundAttributeRequiringCompilation(name);

                flags[aspCompatMode] = Util.GetBooleanAttribute(name, value);

                // Only allow the use of aspcompat when we have UnmanagedCode access (ASURT 76694)
                if (flags[aspCompatMode] && !HttpRuntime.HasUnmanagedPermission())
                {
                    throw new HttpException(SR.GetString(SR.Insufficient_trust_for_attribute, "AspCompat"));
                }

                break;

            case "async":
                // This only makes sense for compiled pages
                OnFoundAttributeRequiringCompilation(name);

                flags[asyncMode] = Util.GetBooleanAttribute(name, value);

                // Async requires Medium trust
                if (!HttpRuntime.HasAspNetHostingPermission(AspNetHostingPermissionLevel.Medium))
                {
                    throw new HttpException(SR.GetString(SR.Insufficient_trust_for_attribute, "async"));
                }

                break;

            case "tracemode":
                // We use TraceModeInternal instead of TraceMode to disallow the 'default' value (ASURT 75783)
                object tmpObj = Util.GetEnumAttribute(name, value, typeof(TraceModeInternal));
                _traceMode = (TraceMode)tmpObj;
                break;

            case "trace":
                bool traceEnabled = Util.GetBooleanAttribute(name, value);
                if (traceEnabled)
                {
                    _traceEnabled = TraceEnable.Enable;
                }
                else
                {
                    _traceEnabled = TraceEnable.Disable;
                }
                break;

            case "smartnavigation":
                // Make sure no device filter or expression builder was specified, since it doesn't make much
                // sense for smartnav (which only works on IE5.5+) (VSWhidbey 85876)
                ValidateBuiltInAttribute(deviceName, name, value);

                // Ignore it if it has default value.  Otherwise, let the generic
                // attribute processing continue
                bool smartNavigation = Util.GetBooleanAttribute(name, value);
                return(smartNavigation == Page.SmartNavigationDefault);

            case "maintainscrollpositiononpostback":
                bool maintainScrollPosition = Util.GetBooleanAttribute(name, value);
                return(maintainScrollPosition == Page.MaintainScrollPositionOnPostBackDefault);

            case "validaterequest":
                flags[validateRequest] = Util.GetBooleanAttribute(name, value);
                break;

            case "clienttarget":
                // Skip validity check for expression builder (e.g. <%$ ... %>)
                if (IsExpressionBuilderValue(value))
                {
                    return(false);
                }

                // Check validity
                HttpCapabilitiesDefaultProvider.GetUserAgentFromClientTarget(CurrentVirtualPath, value);

                // Return false to let the generic attribute processing continue
                return(false);

            case "masterpagefile":
                // Skip validity check for expression builder (e.g. <%$ ... %>)
                if (IsExpressionBuilderValue(value))
                {
                    return(false);
                }

                if (value.Length > 0)
                {
                    // Add dependency on the Type by calling this method
                    Type type = GetReferencedType(value);

                    // Make sure it has the correct base type
                    if (!typeof(MasterPage).IsAssignableFrom(type))
                    {
                        ProcessError(SR.GetString(SR.Invalid_master_base, value));
                    }

                    if (deviceName.Length > 0)
                    {
                        // Make sure the masterPageFile definition from config
                        // is applied before filtered masterPageFile attributes.
                        EnsureMasterPageFileFromConfigApplied();
                    }
                }

                //VSWhidbey 479064 Remember the masterPageFile had been set even if it's empty string
                _mainDirectiveMasterPageSet = true;

                // Return false to let the generic attribute processing continue
                return(false);

            default:
                // We didn't handle the attribute.  Try the base class
                return(base.ProcessMainDirectiveAttribute(deviceName, name, value, parseData));
            }

            // The attribute was handled

            // Make sure no device filter or resource expression was specified
            ValidateBuiltInAttribute(deviceName, name, value);

            return(true);
        }
Esempio n. 6
0
        internal override void ProcessMainDirective(IDictionary mainDirective)
        {
            // Get the error page (if any).
            _errorPage = Util.GetAndRemoveNonEmptyAttribute(mainDirective, "errorpage");

            // Get various attributes

            _clientTarget = Util.GetAndRemove(mainDirective, "clienttarget");

            _contentType = Util.GetAndRemoveNonEmptyAttribute(mainDirective, "contenttype");

            Util.GetAndRemoveBooleanAttribute(mainDirective, "buffer",
                                              ref _fBuffer);

            if (!_fBuffer && _errorPage != null)
            {
                throw new HttpException(
                          HttpRuntime.FormatResourceString(SR.Error_page_not_supported_when_buffering_off));
            }

            string tmp = Util.GetAndRemove(mainDirective, "enablesessionstate");

            if (tmp != null)
            {
                _fRequiresSessionState = true;
                _fReadOnlySessionState = false;
                if (Util.IsFalseString(tmp))
                {
                    _fRequiresSessionState = false;
                }
                else if (string.Compare(tmp, "readonly", true, CultureInfo.InvariantCulture) == 0)
                {
                    _fReadOnlySessionState = true;
                }
                else if (!Util.IsTrueString(tmp))
                {
                    throw new HttpException(
                              HttpRuntime.FormatResourceString(SR.Enablesessionstate_must_be_true_false_or_readonly));
                }
            }

            _culture = Util.GetAndRemoveNonEmptyAttribute(mainDirective, "culture");

            // If it was specified, create a CultureInfo just to verify validity
            if (_culture != null)
            {
                CultureInfo cultureInfo;

                try {
                    cultureInfo = HttpServerUtility.CreateReadOnlyCultureInfo(_culture);
                }
                catch {
                    throw new HttpException(
                              HttpRuntime.FormatResourceString(SR.Invalid_attribute_value, _culture, "culture"));
                }

                // Don't allow neutral cultures (ASURT 77930)
                if (cultureInfo.IsNeutralCulture)
                {
                    throw new HttpException(
                              HttpRuntime.FormatResourceString(SR.Invalid_culture_attribute,
                                                               Util.GetSpecificCulturesFormattedList(cultureInfo)));
                }
            }

            bool fHasLcid = Util.GetAndRemoveNonNegativeIntegerAttribute(mainDirective, "lcid", ref _lcid);

            // If it was specified, create a CultureInfo just to verify validity
            if (fHasLcid)
            {
                try {
                    HttpServerUtility.CreateReadOnlyCultureInfo(_lcid);
                }
                catch {
                    throw new HttpException(
                              HttpRuntime.FormatResourceString(SR.Invalid_attribute_value, _lcid.ToString(), "lcid"));
                }
            }

            if (_culture != null && fHasLcid)
            {
                throw new HttpException(HttpRuntime.FormatResourceString(SR.Attributes_mutually_exclusive, "Culture", "LCID"));
            }

            _uiCulture = Util.GetAndRemoveNonEmptyAttribute(mainDirective, "uiculture");

            _responseEncoding = Util.GetAndRemoveNonEmptyAttribute(mainDirective, "responseencoding");
            // If it was specified, call Encoding.GetEncoding just to verify validity
            if (_responseEncoding != null)
            {
                Encoding.GetEncoding(_responseEncoding);
            }

            bool fHasCodePage = Util.GetAndRemoveNonNegativeIntegerAttribute(mainDirective, "codepage", ref _codePage);

            // If it was specified, call Encoding.GetEncoding just to verify validity
            if (fHasCodePage)
            {
                Encoding.GetEncoding(_codePage);
            }

            if (_responseEncoding != null && fHasCodePage)
            {
                throw new HttpException(
                          HttpRuntime.FormatResourceString(SR.Attributes_mutually_exclusive, "ResponseEncoding", "CodePage"));
            }

            if (mainDirective["transaction"] != null)
            {
                ParseTransactionAttribute(mainDirective);
            }

            if (Util.GetAndRemoveBooleanAttribute(mainDirective, "aspcompat", ref _aspCompatMode))
            {
                // Only allow the use of aspcompat when we have UnmanagedCode access (ASURT 76694)
                if (_aspCompatMode && !HttpRuntime.HasUnmanagedPermission())
                {
                    throw new HttpException(HttpRuntime.FormatResourceString(SR.Insufficient_trust_for_attribute, "AspCompat"));
                }
            }

            // We use TraceModeInternal instead of TraceMode to disallow the 'default' value (ASURT 75783)
            object tmpObj = Util.GetAndRemoveEnumAttribute(
                mainDirective, typeof(TraceModeInternal), "tracemode");

            if (tmpObj != null)
            {
                _traceMode = (TraceMode)tmpObj;
            }

            bool traceEnabled = false;

            if (Util.GetAndRemoveBooleanAttribute(mainDirective, "trace", ref traceEnabled))
            {
                if (traceEnabled)
                {
                    _traceEnabled = TraceEnable.Enable;
                }
                else
                {
                    _traceEnabled = TraceEnable.Disable;
                }
            }

            Util.GetAndRemoveBooleanAttribute(mainDirective, "enableviewstatemac", ref _enableViewStateMac);

            Util.GetAndRemoveBooleanAttribute(mainDirective, "smartnavigation", ref _smartNavigation);

            Util.GetAndRemoveBooleanAttribute(mainDirective, "validaterequest", ref _validateRequest);

            base.ProcessMainDirective(mainDirective);
        }