B
Bruce
I just started the design of an ASP.NET application which accesses one of
our custom web services to provide user authentication, among other
purposes.
I created a log-in page (code below), using the WebControls.Login control.
I put a simple label on the page, to display text showing whether the log-in
was successful. I populate the Label.Text from within the event handler for
the Login control's Authenticate event.
But when I run the page, the label text never shows up on the page. When I
singe step in the debugger, the Label.Text is definately set, but when the
web page is refreshed (after exiting the event handler) the Label text does
not show up on the web page.
I'm new to ASP.NET 2.0, and I assume I am confusing some aspect of the
page/postback lifecyle. Clarifications or recommendations would be greatly
appreciated.
Thanks, Bruce
---------------------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using com.myservice;
public partial class _default : System.Web.UI.Page
{
com.myservice.ReflectionServer m_Server;
com.myservice.UserElements m_user;
protected void Page_Load(object sender, EventArgs e)
{
m_Server = new com.myservice.ReflectionServer();
}
protected void login_Authenticate(object sender, AuthenticateEventArgs e)
{
com.myservice.ReturnData result = new ReturnData();
string userName = login.UserName;
string passWord = login.Password;
result = m_Server.IsAuthenticated(userName, passWord);
if (result.Success)
{
e.Authenticated = true;
labelLogInResult.Text = "Successful Log In";
login.Enabled = false;
m_user = new UserElements();
m_user.userName = userName;
m_user.passWord = passWord;
Application["user"] = m_user;
}
else
{
login.FailureText = "Invalid Username/Password";
labelLogInResult.Text = "Invalid Username/Password";
e.Authenticated = false;
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="default.aspx.cs"
Inherits="_default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body style="font-size: 12pt">
<form id="form1" runat="server">
<div>
<br />
<br />
<asp:Image ID="Image1" runat="server" Height="161px"
ImageUrl="~/images-local/060508-reflection.jpg"
Width="320px" /><br />
<asp:Login ID="login" runat="server" BackColor="#F7F6F3"
BorderColor="#E6E2D8" BorderPadding="4"
BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana"
Font-Size="0.8em"
ForeColor="#333333" style="left: 319px; position: absolute; top:
232px"
OnAuthenticate="login_Authenticate" >
<TitleTextStyle BackColor="Navy" Font-Bold="True"
Font-Size="0.9em" ForeColor="White" />
<InstructionTextStyle Font-Italic="True" ForeColor="Black" />
<TextBoxStyle Font-Size="0.8em" />
<LoginButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC"
BorderStyle="Solid" BorderWidth="1px"
Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284775"
/>
</asp:Login>
<br />
<strong><span style="font-family: Tahoma; color: darkred;">User
Tasks</span></strong><br />
<br />
<span style="font-size: 11pt; font-family: Tahoma">
Create/Modify User Account<br />
Create/Remove/Modify Item<br />
</span>
<br />
<br />
<strong><span style="font-family: Tahoma; color: darkred;">
Administrator Tasks</span></strong><br />
<br />
<span style="font-size: 11pt; font-family: Tahoma">
View Raw Table Contents<br />
Remove a User<br />
Remove an Item</span><br />
<br />
<asp:Label ID="labelLogInResult" runat="server" style="left: 322px;
position: absolute; top: 384px" Height="160px"
Width="203px"></asp:Label></div>
</form>
</body>
</html>
our custom web services to provide user authentication, among other
purposes.
I created a log-in page (code below), using the WebControls.Login control.
I put a simple label on the page, to display text showing whether the log-in
was successful. I populate the Label.Text from within the event handler for
the Login control's Authenticate event.
But when I run the page, the label text never shows up on the page. When I
singe step in the debugger, the Label.Text is definately set, but when the
web page is refreshed (after exiting the event handler) the Label text does
not show up on the web page.
I'm new to ASP.NET 2.0, and I assume I am confusing some aspect of the
page/postback lifecyle. Clarifications or recommendations would be greatly
appreciated.
Thanks, Bruce
---------------------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using com.myservice;
public partial class _default : System.Web.UI.Page
{
com.myservice.ReflectionServer m_Server;
com.myservice.UserElements m_user;
protected void Page_Load(object sender, EventArgs e)
{
m_Server = new com.myservice.ReflectionServer();
}
protected void login_Authenticate(object sender, AuthenticateEventArgs e)
{
com.myservice.ReturnData result = new ReturnData();
string userName = login.UserName;
string passWord = login.Password;
result = m_Server.IsAuthenticated(userName, passWord);
if (result.Success)
{
e.Authenticated = true;
labelLogInResult.Text = "Successful Log In";
login.Enabled = false;
m_user = new UserElements();
m_user.userName = userName;
m_user.passWord = passWord;
Application["user"] = m_user;
}
else
{
login.FailureText = "Invalid Username/Password";
labelLogInResult.Text = "Invalid Username/Password";
e.Authenticated = false;
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="default.aspx.cs"
Inherits="_default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body style="font-size: 12pt">
<form id="form1" runat="server">
<div>
<br />
<br />
<asp:Image ID="Image1" runat="server" Height="161px"
ImageUrl="~/images-local/060508-reflection.jpg"
Width="320px" /><br />
<asp:Login ID="login" runat="server" BackColor="#F7F6F3"
BorderColor="#E6E2D8" BorderPadding="4"
BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana"
Font-Size="0.8em"
ForeColor="#333333" style="left: 319px; position: absolute; top:
232px"
OnAuthenticate="login_Authenticate" >
<TitleTextStyle BackColor="Navy" Font-Bold="True"
Font-Size="0.9em" ForeColor="White" />
<InstructionTextStyle Font-Italic="True" ForeColor="Black" />
<TextBoxStyle Font-Size="0.8em" />
<LoginButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC"
BorderStyle="Solid" BorderWidth="1px"
Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284775"
/>
</asp:Login>
<br />
<strong><span style="font-family: Tahoma; color: darkred;">User
Tasks</span></strong><br />
<br />
<span style="font-size: 11pt; font-family: Tahoma">
Create/Modify User Account<br />
Create/Remove/Modify Item<br />
</span>
<br />
<br />
<strong><span style="font-family: Tahoma; color: darkred;">
Administrator Tasks</span></strong><br />
<br />
<span style="font-size: 11pt; font-family: Tahoma">
View Raw Table Contents<br />
Remove a User<br />
Remove an Item</span><br />
<br />
<asp:Label ID="labelLogInResult" runat="server" style="left: 322px;
position: absolute; top: 384px" Height="160px"
Width="203px"></asp:Label></div>
</form>
</body>
</html>