This page
HTTP header and user agent Determine browser features to map headers to browser feature superior browser and subsequent browser define new browser tests to create their own target HTMLTextWriter and HTMLTextWriter32 mobile browser features Summary
The web application is different from other applications running in homologous environments, as the former will send the output to a wide variety of platforms and web browsers. Some browsers support the client script, some support XHTML, and some will limit the screen area. So how do your web application pass the content to a restriction function or a special requirements?
In order to answer this question, I will study the support of ASP.NET 1.1 to determine the functionality of the browser. To see the upcoming features in ASP.NET 2.0, see the Browser Bar "ASP.NET 2.0 Browser". [Edit Update - December 14, 2004: The bar bar has been updated. ]
HTTP header and user agent
Determine the first step in the browser feature that will be sent to your web site is to identify which type of browser belongs to. The payload sent in the HTTP header contains a user agent string that describes a request for a browser. Although, you can usually see the header sent by the client browser to the remote web site, but you can use the TCP trace application to view. I use TCPTrace (an application written by Simon Fell and Matt Humphrey) to verify the header. Figure 1 shows a header dump of a web request.
Note the user agent string in Figure 2. In your ASP.NET application, you can easily extract strings from the header collection by programming. You can also view the user agent string as shown in Figure 3 when tracing is enabled in your application.
Figure 3 shows the http_user_agent string
This is smooth, but what can you use this information? They will only be useful when you know what is added to each browser version. In traditional ASP and ASP.NET, various browser functions are recorded in the auxiliary file.
Back to top
Determine the browser function
In traditional ASP, DLL% windir% / system32 / inetsrv / browscap.dll contains a class that determines the functionality of the browser based on incoming user agent strings. The browser function object checks% windir% / system32 / inetsrv / browscap.ini to match the user agent string with the .ini file, which describes some of the well-known functions of this browser. (The ATL server is a C template library for creating an ISAPI DLL. It also uses browscap.ini to determine the browser feature. For more information on the ATL server, check the ASP column in the November 2003 issue of MSDN® Magazine.)
Figure 4 shows a part of the browscap.ini file that illustrates your ability to identify your browser for Microsoft® Internet Explorer 2.0. This part. INI file indicates that Internet Explorer does not support client scripts and does not support Java applets.
To use information in the traditional ASP application, you must create a browsertype object in the script (it is a COM object with "mswc.browsertype") and queries its properties to get the name, version, and Whether to support cookie and other information. You can accurately transfer your content through this information.
The ASP.NET contains the HTTPBrowserCapabilities class for querying browser features. The HTTPRequest class contains references to instances of the HTTPBrowserCapAbilties class, so it is usually available throughout the application. You can extract it from the current instance of the current Page instance or the HTTPContext class. HttpBrowserCapabilities contains many properties and its meaning, as you can see in Figure 5. Most browser features are obvious, you can use the information provided to adjust your output. For example, if you have a script, you only send it to the client when the other end browser understands it, and I use the code in Figure 6.
Back to top
Map the header to the browser function
In the September issue of this column, I saw ASP.NET configuration and how ASP.NET uses a specific handler to interpret individual parts in the configuration file. Now let's take a look at the various parts of the Machine.config file, the machine.config file is the starting point configured in the ASP.NET. At the location close to the top of the file, you will see a node that provides a component name that explains the user agent string to determine the functionality of the browser:
TYPE = "System.Web.configuration.httpcapabilitiessectionHandler, System.Web, Version = 1.0.5000.0, Culture = neutral, PublicKeyToken = B03F5F7F11D50A3A "/> ... sectiongroup> As you can see, the type named "httpcapabilitiessectionhandler" is used to parse the The Platform = WinXP case> Platform = Win2000 case> Back to top The superior browser is as defined in Machine.config, as defined in Machine.config, is divided into two main types: superiors and subordinates. The upper browser supports HTML 4.0, a stacked style sheet, ECMAScript 1.2 (JScript® and JavaScript), and a Document Object Model with W3C compatible document object. The lower browser and client devices support only HTML 3.2. Using the difference between the browser, how the Web site will change when accessing the Web site in the most common use case. Most modern browsers are mentioned in Machine.Config. If a browser is not defined there, you can easily add the definition to the web.config for your application. Back to top Define new browsers As almost all other configuration settings mentioned in Machine.Config are extension, the browser's function settings can also be extended. Suppose there is an unknown browser that you need to tailor your site. In order to support the functionality of the new browser, create a separate This is used to tell ASP.NET has a new browser called "LameBrowser". A definition is given in the Back to top test If you have a replica of the target browser in your test environment, you can easily understand how your Web site responds. If not, ASP.NET supports an aliasing technology that enables you to force an application to think that a browser has issued a request. You will find the "Mozilla / 4.0 (Compatible; Msie 5.5; Windows NT 4.0)" /> "Mozilla / 4.0 (Compatible; Msie 4.0; Windows NT 4.0)" /> "Mozilla / 4.0 (Compatible; Msie 4.0; Windows NT 4.0)" /> clientTarget> As you can see, the Inherits = "browsercapabilitysite.webform1" ClientTarget = "UPLEVEL"%> This allows you to display the page presenting in different browsers. Back to top Create your own goal Although ASP.NET provides you with four built-in target alias, you may benefit from more aliases. For example, suppose you want to test your site via the Firefox browser or the LameBrowser mentioned earlier. The XML bits in your web.config file will complete this task below (assuming that you have set each clientTarget> Back to top HtmlTextWriter and HtmlTextWriter32 In addition to the properties shown in Figure 5, HttpBrowSerCapabilities also discloses another read-only attribute called TagWrite. TagWriter property Open class, used to present tags in the control. If you have written custom server-side controls, you have no doubt that HTMLTextWriter classes that are passed to the Render method. You may think that from the server-side control call Output.write is the same as that call response.write, but in fact, the former is more flexible than the latter. HTMLTextWriter contains methods for presenting a particular HTML element. Although the other ASP.NET server-side controls are usually very good when writing custom controls, but sometimes you need to manually process tags. Some methods including the HTMLTextWriter class can support stack rendering tags and properties. In addition to saving you to save start and end tags, HTMLTextWriter can help you publish the correct version of HTML. When ASP.NET gets a request, it checks the TagWriter property of the HTTPBrowserCapabilities class and uses HTMLTextWriter or HTML32TextWriter (HTML32TextWriter to HTMLTextWriter). For example, in HTML 3.2 and HTML 4.0, the presentation will be slightly different. The code segment in Figure 9 (the render method overwritten in the server-side control) presents a simple table with only one line and a column. HTMLTextWriter includes a method of rendering attributes and tags based on the HTML version of the browser. Below is the way HTML32TextWriter rendered table