tag, yes. The following ASPX file displays the "Products" table of SQL Server's Northwind database in a scrolling table:
<%@ Import Namespace="System.Data.SqlClient" %>
--------------------------------------------------------------------------------
By default, ASP.NET's worker process uses the identity of a special account named ASPNET that's created when ASP.NET is installed. By including
a user name and password in Machine.config's element, I can configure ASP.NET to run using an account of my choosing. However, my company has a
strict policy against encoding plaintext passwords in configuration files. I want to specify the account that ASP.NET uses, but I also need to
secure the password. Is that possible?
Out of the box, ASP.NET 1.0 requires the user name and password to be encoded in plaintext in Machine.config. However, you can obtain a patch
from Microsoft that allows the user name and password to be stored in encrypted form in a secure registry key that's off limits to non-administrators.
The hotfix also allows you to secure the credentials used to access ASP.NET's ASPState database when using SQL Server to store session state.
You'll find instructions for obtaining the hotfix (and information about a helper utility that encrypts user names and passwords for you)
at http://support.microsoft.com/default.aspx?scid=kb;en-us;Q329250. Microsoft plans to build the hotfix into the “Everett" release of the .NET
Framework, which will ship with Windows .NET Server. Be aware, however, that Windows .NET Server comes with IIS 6.0, which supports an alternative
means for securing process credentials. Applications can be assigned to arbitrary application pools, and application pools can be assigned unique
identities using encrypted credentials stored in the IIS metabase. As Microsoft security guru Erik Olsen recently noted, this is probably the better
long-term direction for companies whose policies prevent them from storing plaintext credentials in CONFIG files.
--------------------------------------------------------------------------------
I want to make DataGrid paging more efficient by using custom paging. Oracle makes custom paging easy by supporting query-by-row-number.
SQL Server is just the opposite. There's no obvious way to ask SQL Server for, say, rows 101-150 in a 500-row result set. What's the best way
to do custom paging when you have SQL Server on the back end?
You can use a query of the following form to retrieve records by row number from Microsoft SQL Server:
SELECT * FROM
(SELECT TOP {0} * FROM
(SELECT TOP {1} * FROM {2}
ORDER BY {3}) AS t1
ORDER BY {3} DESC) AS t2
ORDER BY {3}
Replace {0} with the page size (the number of records displayed on each page), {1} with the page size * page number (1-based), {2} with the
name of the table you wish to query, and {3} with a field name. The following example retrieves rows 41-50 from the "Products" table of the
Northwind database:
SELECT * FROM
(SELECT TOP 10 * FROM
(SELECT TOP 50 * FROM Products
ORDER BY ProductID) AS t1
ORDER BY ProductID DESC) AS t2
ORDER BY ProductID
You can combine this query technique with custom paging to make DataGrid paging more efficient. With default paging, you must initialize the
data source with all records displayed on all pages. With custom paging, you can initialize the data source with just those records that pertain
to the current page.
--------------------------------------------------------------------------------
Is it possible to prevent a Web form from scrolling to the top of the page when it posts back to the server?
One way to do it is to add a SmartNavigation="true" attribute to the page's @ Page directive. That requires Internet Explorer 5.0 or higher on
the client. To prevent unwanted scrolling in a wider range of browsers, you can use a server-side script that generates client-side script.
The first step is to replace the page's tag with the following statements:
<%
if (Request["__SCROLLPOS"] != null &&
Request["__SCROLLPOS"] != String.Empty) {
int pos = Convert.ToInt32 (Request["__SCROLLPOS"]);
Response.Write (" "onscroll=\"javascript:document.forms[0].__SCROLLPOS.value = "
"theBody.scrollTop;\" "
"onload=\"javascript:theBody.scrollTop=" pos ";\">");
}
else {
Response.Write (" "onscroll=\"javascript:document.forms[0].__SCROLLPOS.value ="
"theBody.scrollTop;\">");
}
%>
Step two is to add the following line somewhere between the
tags:
How does it work? The server-side script block outputs a tag containing an onscroll attribute that keeps tabs on the scroll position
and an onload attribute that restores the last scroll position following a postback. The scroll position is transmitted to the server in a
hidden
control named __SCROLLPOS. Note that this technique is compatible with Internet Explorer but not with Netscape Navigator.
--------------------------------------------------------------------------------
If I use the same user control in two different pages and include an @ OutputCache directive in the ASCX file, will the user control be cached
once or twice?
In ASP.NET version 1.0, the control will be cached twice. In version 1.1, you can include a Shared="true" attribute in the @ OutputCache directive
to cache the control just once.
--------------------------------------------------------------------------------
What's the best source of in-depth information on ASP.NET security?
Go to http://www.microsoft.com/downloads/release.asp?ReleaseID=44047 and download a free book (in PDF format) from Microsoft entitled
"Building Secure ASP.NET Applications." At 608 pages, it's packed with more than you'll probably ever need to know about ASP.NET security.
An awesome resource for ASP.NET developers!
--------------------------------------------------------------------------------
How do I set the focus to a specific control when a Web form loads?
With a dash of client-side script. Upon loading, the following page sets the focus to the first of its three TextBox controls: