BrowserCaps and browser function settings, browsercaps

Source: Internet
Author: User

BrowserCaps and browser function settings, browsercaps

The browserCaps element in the Web. config file is used to define the browser behavior. NET Framework 2.0 is rejected, but it is still supported. The data in this element is combined with the information in the browser definition file (. browser. In this study, the related content of the. browser file will be associated.

Element

Description

Filter

Optional.

Specify the search string list. You can use these strings to apply each setting to a specific browser.

Result

SpecifyHttpCapabilitiesBaseA derived class used to save the analysis.BrowserCaps. These functions are stored as key/value string pairs for each browser.

This element is still applicable in. NET Framework 2.0.

Use

Specifies the HTTP request string, which is used for analysis and storage inFilterAndCaseThe browser function information in the element.

In addition, the filter contains the sub-element case, and the case is the result saved after the filter is filtered. The result is saved as a key-value pair to the type of execution in result. The filtered object is the HTTP header request field specified in the use element.

In the following configuration, the matched USER-AGENT contains Chrome/52.0.2743.116, and the functional settings for the browser are browser-to-cookies.

<browserCaps><use var="HTTP_USER_AGENT"/><filter><case match="Chrome/52.0.2743.116">browser=Chromeversion=52majorver=52minorver=0hopegi=mr.hopegicookies=false</case></filter></browserCaps>

 

To obtain the function of the browser in the code, use the following method.

object cookies = Request.Browser.Cookies;cookies = Request.Browser["cookies"];var hg = Request.Browser["hopegi"];

According to fengge, *. broswer files are used to determine the type of browser sent by the current request to IIS. After determining the browser type, make different changes to the response or response content. If a browser is not recognized and the default browser does not support cookies, the authentication ticket will not be saved to the browser in the form of cookies during Forms authentication, as a result, the browser may fail to pass authentication.

The *. browser file is released in. NET Framework2.0. The example is as follows:

User-Agent matching is in the userAgent match section. The browser functions are defined in the <capabilities> section.

The predefined browser definition file is stored in % SystemRoot % \ Microsoft. NET \ Framework \Version\ CONFIG \ Browsers directory. Application-level browser definition files can be placed in the App_Browsers directory of the application. In both locations, the browser definition file must have the. browser file extension. Do not change the browser definition files included with ASP. NET, because Service Pack may update these files to rewrite your changes. Instead, you should create a new. browser file andBrowserUsed in DefinitionParentIDProperty to inherit the settings, or useRefIDAttribute to the existing browser definition.

At runtime, the browser definition file information will be merged into a set of known browsers in the BrowserCapabilitiesFactory object. When a request is sent, ASP. NET identifies the requested browser based on the request header and compiles an HttpBrowserCapabilities object corresponding to the requested browser type. This step is done in this way: use an empty dictionary at the beginning, and then apply the following recursive steps to the browser definition tree:

HttpBrowserCapabilitiesThe object is written to the cache and can be used again by other requests from the same type of browser.

Changes made to the. browser file in the App_Browsers directory will invalidate the cache, And the next request will cause the application to recompile. However, if % SystemRoot % \ Microsoft.. NET \ Framework \ version \ CONFIG \ Browsers directory. the browser file has been changed. You must use % SystemRoot % \ Microsoft. NET \ Framework \ version \ aspnet_regbrowsers.exe tool to manually re-compile the application, or use the BrowserCapabilitiesCodeGenerator class to re-compile the application programmatically.

To sum up, both the browserCaps element and the browser file are used to define the features of the browser. For the browser, the browser sends the request to the server and notifies the server that its information is in the User-Agent request header. The server determines which browser the request comes from or even which functions the browser that sends the request currently has. In this case, the configuration information set for this browser function is required. It matches the request header information (usually User-Agent) and determines the browser type after successful matching. And then determine the features of the browser. In addition, it is depressing that the browser files in the App_Browser folder created in the application directory do not take effect.

Reference

BrowserCaps element (ASP. NET architecture)

Https://msdn.microsoft.com/zh-cn/library/sk9az15a (VS.80). aspx

Browser-defined file architecture (browsers element)

Https://msdn.microsoft.com/zh-cn/library/ms228122 (v = vs.80). aspx

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.