Figure 4
Figure 4
IIDentity Members
Property |
Description |
AuthenticationType |
Reveals what form of authentication was used |
IsAuthenticated |
Reveals whether the user is authenticated |
Name |
Reveals an authenticated user's name |
Figure 5
CorpNet Source Code General.aspx
<%@ Page Language="C#" %>
<html>
<body>
<h1>Welcome to CorpNet!</h1>
<hr>
Welcome to the corporate intranet! We don't have a lot to offer
right now, but check back in a few days and we'll have information
regarding the massive layoff that has been the subject of so many
rumors. Do remember, though, that we're watching you all the time.
We even know who you are because you had to provide a user name
and password to see this page. To prove it, your user name is
shown below.<br>
<h3>
<%
if (User.Identity.IsAuthenticated)
Response.Write (User.Identity.Name);
%>
</h3>
</body>
</html>
Salaries.aspx
<%@ Page Language="C#" %>
<html>
<body>
<h1>Salaries</h1>
<hr>
<%
if (!User.Identity.IsAuthenticated)
Response.Write ("Sorry, but no salary information " +
"is available for unauthenticated users.");
else {
if (User.Identity.Name.IndexOf ("Jeff") != -1)
Response.Write ("Jeff's salary is $10,000.");
else if (User.Identity.Name.IndexOf ("John") != -1)
Response.Write ("John's salary is $20,000.");
else if (User.Identity.Name.IndexOf ("Bob") != -1)
Response.Write ("Bob's salary is $30,000.");
else if (User.Identity.Name.IndexOf ("Alice") != -1)
Response.Write ("Alice's salary is $40,000.");
else if (User.Identity.Name.IndexOf ("Mary") != -1)
Response.Write ("Mary's salary is $50,000.");
else
Response.Write ("No salary information is " +
"available for " + User.Identity.Name);
}
%>
</body>
</html>
Bonuses.aspx
<%@ Import Namespace="System.Data" %>
<html>
<body>
<asp:DataGrid ID="MyDataGrid" Width="40%" RunAt="server" />
<asp:Label ID="Output" RunAt="server" />
</body>
</html>
<script language="C#" runat="server">
void Page_Load (Object sender, EventArgs e)
{
try {
DataSet ds = new DataSet ();
ds.ReadXml (Server.MapPath ("Bonuses.xml"));
MyDataGrid.DataSource = ds;
MyDataGrid.DataBind ();
}
catch (Exception) {
Output.Text = "An error occurred processing this page.";
}
}
</script>
Bonuses.xml
<?xml version="1.0" encoding="UTF-8"?>
<Bonuses>
<Bonus>
<Name>Jeff</Name>
<Amount>1000</Amount>
</Bonus>
<Bonus>
<Name>John</Name>
<Amount>2000</Amount>
</Bonus>
<Bonus>
<Name>Bob</Name>
<Amount>3000</Amount>
</Bonus>
<Bonus>
<Name>Alice</Name>
<Amount>4000</Amount>
</Bonus>
<Bonus>
<Name>Mary</Name>
<Amount>5000</Amount>
</Bonus>
</Bonuses>
Web.config
<configuration>
<system.web>
<authentication mode="Windows" />
</system.web>
</configuration>