Last Updated: 4/2002
Caching |
Where a large amount of processing is required to output a page (e.g. a timetable) it can be marked for placement in an outgoing cache for a specific period of time. Requests for that page will then return that page until the first request following the specified time period which in turn will then be cached again for the specified period.
Items can also be read and written directly from and to the cache:
|
Configuration Files |
%Winnt%\Microsoft.NET\Framwork\v...\config\machine.config Note: |
Cookies |
Test for an existing cookie by comparing the appropriate entry from Request.Cookies with null, for example:
A new cookie is created in the same way as any other object:
and also has to be added to the collection as normal, although the method name for doing so is non-standard:
Cookies are normally deleted at the end of a session. To make a cookie live beyond that point it's expiry date needs to be set, for example:
Note: Only the first 4096 of a cookie are guaranteed to be stored. ?? How to test to see if cookies are enabled on user's browser? ?? |
Note: Haven't tried it because (a) I don't think it will work unless the IIS server is also configured as a SMTP server and (b) the "myMail.Body = myMessage;" line looks like it needs to be fleshed out. The default regular expression validator shipping with .NET v1.0 is not RFC822 compliant. The following expression is closer:
|
Getting Session (etc.) Info When Not on a Page |
System.Web.HttpContext.Current contains references for the following objected normally access via the Page object:
This is very useful to know when working outside of the Page / Control environment. |
Graphics Server |
(Drawing to a bitmap, then returning the image)
Example (Note: This is a simplification of the test code I wrote, so may be missing some required libraries etc.): GraphicsServer.asp (we could place all the code here, but by placing in a code-behind file we get better compile time checking)
GraphicsServer.cs
|
Navigator Object |
A browser thing rather than a C# or ASP thing. Supported both in IE & Netscape (although Netscape returns "undefined" for many of these properties). Contains useful properties such as:
|
Reading User-Defined Application Settings |
Add a reference to the settings file in the main config file (normally web.config for asp projects) using the appSettings tag. Use the add tag to provide default key & value pairs in case the config file you supply is missing (or doesn't specify the requisite key):
In the file referenced in the above snippet (normally this is called user.config rather than placeholder shown), place overrides for the relevant settings :
To obtain the value associated with a specific key at run-time, use:
|
System.Net.WebRequest allows web requests to be made
programmatically and the results accessed both synchronously and asynchronously.
Only files that the user can normally access are available this way. For
example, .config files cannot be accessed.
|
Restarting IIS |
Enter iisreset at the command line. A remote pc can be specified (iisreset \\somepc). PC can also be rebooted (iisreset /reboot) |
Security |
To obtain the end-user's NT domain login:
|
Smart Navigation |
Normally when a page is refreshed the user is returned to the top of the page, the current focus is moved to the first control in the tab order and there is considerable flicker as the display is rebuilt. By adding SmartNavigation="true" to the @Page line, IE5 will leave the page and focus where it is and refresh the form flicker free. This actually makes a lot of difference to the overall refresh effect. This can be set globally for a site by modifying config.web and adding <pages smartNavigation="true" /> to the <system.web> tag. There are numerous known difficulties with Smart Navigation and complex web-pages, making it unsuitable for some applications. |
Unit Class |
Use to convert between objects that record their dimensions in different units. For example, a textbox is in points but you have a control next to it that is measures in pixels. Unit is like the Convert class. |
ViewState |
See also: ?? Partially covered elsewhere ?? ASP.NET controls can save their internal state between requests using that control's StateBag's ViewState collection:
|
Writing to the Response Object |
There are several ways to get content directly into the returned "page":
By default the "page" to be returned to the client is completely generated in a server-side buffer until the "page" is complete and then sent to the client. Thus, Response.Clear() will wipe the entire page ensuring a blank starting point for the creation of customised returned results. However, there is a property (BufferedOutput) that can be changed so that the page is sent piece-by-piece to the client as it is constructed. ?? Is it possible to force buffering even on a system with buffering disabled using <%@Page Buffer=true%> ? ?? Response.End() Note: "Response" is actually "Page.Response", which is a property that points to a HTTPResponse object. |