/// <summary> /// Constructs an instance of <cref see="MobileCapabilitiesProvider"/>. /// All default values remain the same and are unaltered. /// </summary> /// <param name="parent"></param> public MobileCapabilitiesProvider(HttpCapabilitiesDefaultProvider parent) : base(parent) { EventLog.Debug("Constructing MobileCapabilitiesProvider with parent"); #if DEBUG LogStackTrace(); #endif }
/// <summary> /// Constructs an instance of <cref see="MobileCapabilitiesProvider"/>. /// Sets the cache key length to a value of 256 to allow for mobile /// useragents that can often be longer than the default 64 characters. /// </summary> public MobileCapabilitiesProvider(HttpCapabilitiesDefaultProvider parent) : base(parent) { EventLog.Debug("Constructing MobileCapabilitiesProvider - HttpCapabilitiesDefaultProvider"); #if DEBUG LogStackTrace(); #endif _parent = parent; base.UserAgentCacheKeyLength = 256; }
GetBrowserCapabilities(HttpRequest request) { HttpCapabilitiesDefaultProvider defaults = new HttpCapabilitiesDefaultProvider(); HttpBrowserCapabilities caps = defaults.GetBrowserCapabilities(request); if (request.UserAgent.Contains("Kindle Fire")) { caps.Capabilities["Browser"] = "Silk"; caps.Capabilities["IsMobileDevice"] = "true"; caps.Capabilities["MobileDeviceManufacturer"] = "Amazon"; caps.Capabilities["MobileDeviceModel"] = "Kindle Fire"; if (request.UserAgent.Contains("Kindle Fire HD")) { caps.Capabilities["MobileDeviceModel"] = "Kindle Fire HD"; } } return(caps); }
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); }
/// <summary> /// Constructor /// </summary> /// <param name="parent"> /// The <see cref="HttpCapabilitiesDefaultProvider"/> instance to use /// for initializing a new instance. /// </param> public CapabilitiesProvider(HttpCapabilitiesDefaultProvider parent) : base(parent) { }
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); }