473,396 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

unexpected authectication behavior in ASP.NET example app. Apress

Hi,
I am following along an example from the book <b>Beginning Visual Web
Programming in C#</b>

My environment is this:
IIS 5.1 on XP Pro, I have the checkbox 'use windows integrated
authentication' unchecked, and I am allowing anonymous access.

Prior to building the example that is giving the error, the app would ask
you to login if you weren't already logged in by redirecting you to the login
page.

In the case of the example, for testing purposes you are instructed to enter
a url with a parameter appened to the URL. What is supposed to happen is
you will be redirected to the login page, then once you login you should be
redirected back to the original page that was in the url with the appended
parameter, that parameter being used to pull some data from the db and
display on this page.

I have carefully checked my code, and even used the authors code downloaded
from apress with the same error. I will post the code, but what I am really
looking for is a general guideline how to debug this issue. I am wondering if
this is a bug, or error in their program.

I am new to C# and asp.net, looking at this as a learning opportunity, but
also feeling frustrated.

viewuser.aspx
<code>
<%@ Page language="c#" Codebehind="viewuser.aspx.cs" AutoEventWireup="false"
Inherits="FriendsReunion.viewuser" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>viewuser</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<LINK href="styles/iestyle.css" type="text/css" rel="stylesheet">
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<TABLE class="TableLines" id="tbLogin" cellSpacing="2" cols="2"
cellPadding="2" border="0">
<TR>
<TD align="right" colSpan="1" rowSpan="1">
<P align="right">name:</P>
</TD>
<TD>
<asp:Label id="lblName" runat="server"
Text='<%# dsUser.Tables[0].Rows[0]["FirstName"] + " " +
dsUser.Tables[0].Rows[0]["LastName"] %>'>
</asp:Label>
</TD>
</TR>
<TR>
<TD>birth date:</TD>
<TD>
<asp:Label id="lblBirth" runat="server"
Text='<%#
DataBinder.Eval(dsUser.Tables[0].Rows[0],"[DateOfBirth]","{0:MMMM dd,
yyyy}")%>'>
</asp:Label>
</TD>
</TR>
<TR>
<TD>
<P align="right">phone number:</P>
</TD>
<TD>
<asp:Label id="lblPhone" runat="server"
Text='<%#
DataBinder.Eval(dsUser.Tables["User"].Rows[0],"[PhoneNumber]") %>' >
</asp:Label>
</TD>
</TR>
<TR>
<TD>
<P align="right">mobile number:</P>
</TD>
<TD>
<asp:Label id="lblMobile" runat="server"
Text='<%# dsUser.Tables["User"].Rows[0]["CellNumber"] %> '>
</asp:Label>
</TD>
</TR>
<TR>
<TD>
<P align="right">address:</P>
</TD>
<TD>
<asp:Label id="lblAddress" runat="server"
Text='<%#
DataBinder.Eval(dsUser.Tables["User"].Rows[0],"[Address]") %> '>
</asp:Label>
</TD>
</TR>
<TR>
<TD>
<P align="right">email:</P>
</TD>
<TD>
<asp:HyperLink id="lnkEmail" runat="server"
NavigateUrl='<%#
DataBinder.Eval(dsUser.Tables["User"].Rows[0],"[email]","mailto:{0}") %> '>
send mail</asp:HyperLink>
</TD>
</TR>
</TABLE>
<P>the user
<asp:Label id="lblPending" runat="server"
Text='<%# GetPending() %>'>
</asp:Label> requests for contact is pending.</P>
<asp:Button id="btnAuthorize" runat="server" Text="authorize
contact"></asp:Button>
</form>
</body>
</HTML>
</code>
viewuser.aspx.cs
<code>

using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace FriendsReunion
{
/// <summary>
/// Summary description for viewuser.
/// </summary>
public class viewuser : FriendsBase
{
protected System.Web.UI.WebControls.Label lblName;
protected System.Web.UI.WebControls.Label lblBirth;
protected System.Web.UI.WebControls.Label lblPhone;
protected System.Web.UI.WebControls.Label lblMobile;
protected System.Web.UI.WebControls.Label lblAddress;
protected System.Web.UI.WebControls.Label lblPending;
protected System.Web.UI.WebControls.HyperLink lnkEmail;
protected System.Web.UI.WebControls.Button btnAuthorize;
protected DataSet dsUser;

private void Page_Load(object sender, System.EventArgs e)
{
string userID = Request.QueryString["RequestID"];

//ensure we receive an ID
if (userID == null)
throw new ArgumentException("this page expects a RequestID parameter");

//create the connection and data adaptor
SqlConnection cnFriends = new SqlConnection(
ConfigurationSettings.AppSettings["cnFriends.ConnectionString"]);
SqlDataAdapter adUser = new SqlDataAdapter(
"SELECT * FROM [User] WHERE UserID=@ID", cnFriends);
adUser.SelectCommand.Parameters.Add("@ID", userID);

//initialize the dataset and fill it with data
dsUser = new DataSet();
adUser.Fill(dsUser, "User");

//finally, bind all controls on the page 'one control to rule.... and in
the darkness
//bind them'. no wait wrong venue!
this.DataBind();
}

protected string GetPending()
{
//create the connection and command to execute
SqlConnection cnFriends = new SqlConnection(
ConfigurationSettings.AppSettings["cnFriends.ConnectionString"]);
SqlCommand cmd = new SqlCommand(
@"SELECT COUNT(*) FROM Contact
WHERE IsApproved=0 AND DestinationID=@ID",
cnFriends);
cmd.Parameters.Add("@ID", Page.User.Identity.Name);
cnFriends.Open();

try
{
return cmd.ExecuteScalar().ToString();
}
finally
{
cnFriends.Close();
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnAuthorize.Click += new
System.EventHandler(this.btnAuthorize_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnAuthorize_Click(object sender, System.EventArgs e)
{
//create the connection and command to execute
SqlConnection cnFriends = new SqlConnection(
ConfigurationSettings.AppSettings["cnFriends.ConnectionString"]);
SqlCommand cmd = new SqlCommand(
@"UPDATE Contact
SET IsApproved=1
WHERE
RequestID=@RequestID AND DestinationID=@DestinationID",
cnFriends);
cmd.Parameters.Add("@RequestID", Request.QueryString["RequestID"]);
cmd.Parameters.Add("@DestinationID", Page.User.Identity.Name);

cnFriends.Open();

try
{
cmd.ExecuteNonQuery();
}
finally
{
cnFriends.Close();
}
//return to the news page
Response.Redirect("news.aspx");

}
}
}
</code>
Nov 16 '05 #1
1 1417
The actual error that I am getting is
Login Failed for user '[my computer name\ASPNET'

This happens when the page is redirected to the login page, and I login
with a user that exists in the database. If I go back to the page, using
the back button I can see that I am in fact logged in as that user, but I
can't access that page
(viewuser.aspx)

Thanks in Advance.

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Attila Feher | last post by:
Hi all, I have not done much work around exceptions; and even when I do I avoid exception specifications. But now I have to teach people about these language facilities, so I am trying them out...
7
by: Dave Hansen | last post by:
OK, first, I don't often have the time to read this group, so apologies if this is a FAQ, though I couldn't find anything at python.org. Second, this isn't my code. I wouldn't do this. But a...
4
by: Generic Usenet Account | last post by:
I am seeing some unexpected behavior while using the STL "includes" algorithm. I am not sure if this is a bug with the template header files in our STL distribution, or if this is how it should...
5
by: Timothy Perrigo | last post by:
This bug? feature? caused a bit of havoc for us yesterday...A reproducible example follows. Essentially, if you have a table with a primary key called "id", and you create a temp table (via a...
6
by: Samuel M. Smith | last post by:
I have been playing around with a subclass of dict wrt a recipe for setting dict items using attribute syntax. The dict class has some read only attributes that generate an exception if I try to...
9
by: Jeff Louie | last post by:
In C# (and C++/cli) the destructor will be called even if an exception is thrown in the constructor. IMHO, this is unexpected behavior that can lead to an invalid system state. So beware! ...
62
by: ashu | last post by:
hi look at this code include <stdio.h> int main(void) { int i,j=2; i=j++ * ++j * j++; printf("%d %d",i,j); return 0;
4
by: duffdevice | last post by:
Hi, I came across this unexpected behavior while working on something else. I am attempting to return a custom type by value from a global function. I have a trace in the custom class's copy...
2
by: Dimitri Furman | last post by:
SQL Server 2000 SP4. Running the script below prints 'Unexpected': ----------------------------- DECLARE @String AS varchar(1) SELECT @String = 'z' IF @String LIKE ''
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.