Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 15th, 2006, 11:12 PM
Registered User
 
Join Date: Sep 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Redirect Problems

I am using Web.Config to do authentication like so:

(Web.Config)
<authentication mode="Forms">
<forms name="LoginGradeBook" loginUrl="login.aspx">
    <credentials passwordFormat="Clear">
    <user name="admin" password="password"/>
    </credentials>
</forms>
</authentication>


I am using Visual Studio 2005 to create a Login Control box which has username/password built-in to it. I believe it is authenicating, but it continues to send me to default.aspx page when it authenticates properly. The problem is... there is no default.aspx. I need it to redirect to otherPage.aspx.

Here is my code:

(Login.aspx)
Protected Sub LoginGradeBook_Click(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles LoginGradeBook.Authenticate

If FormsAuthentication.Authenticate(LoginGradeBook.Us erName, LoginGradeBook.Password) Then

FormsAuthentication.RedirectFromLoginPage(LoginGra deBook.UserName, True)

Else
            Response.Write("Invalid Credentials")

End If

End Sub


So, after it authenticates ... it sends me to the default.aspx page, instead of the otherPage.aspx. If anyone knows what I am missing, I'd appreciate any info you can offer.

If you didn't already assume this ... the login server control is named LoginGradeBook and I HAVE set the DestinationPageUrl property to point to OtherPage.aspx.

Thanks!

Faithful

 
Old September 16th, 2006, 05:42 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Is there any reason you're manually calling FormsAuthentication.RedirectFromLoginPage?

This is normally all taken care of by the .NET Framework. All you need is a Login control and not much more....

By calling RedirectFromLoginPage I think te destination URL is ignored...

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old September 16th, 2006, 10:37 AM
Registered User
 
Join Date: Sep 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply Imar.

I am new to Visual Studio and ASP.net for that matter.

So, If I take that chunk of code out, it just continues to tell me
that my password is incorrect. I didn't modify my web.config file again, so do you have any idea why it is not working?

 
Old September 16th, 2006, 10:46 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Things have changed a lot since .NET 1.x.

In ASP.NET 2, you have easy user management through a number of security features. This uses a SQL Server database to store user names, passwords on so on. Normally, you don't need to do anything to make this work. Drop a Login control on a page, run it, and try to log in. This will fail, but you end up with a database in your App_Data folder.

Next, choose Website| ASP.NET COnfiguration in Visual Web Developer to start the WSAT. This tool allows you to create new users, manage roles and so on.

Take a look here for more info:

http://quickstarts.asp.net/QuickStar...y/default.aspx

Alternatively, if you decide to stick to "classic" authentication, add a defaultUrl attribute to your <forms> element, like this:
Code:
<authentication mode="Forms">
  <forms name="LoginGradeBook" loginUrl="login.aspx" defaultUrl="SomePage.aspx">
    <credentials passwordFormat="Clear">
      <user name="admin" password="password"/>
    </credentials>
  </forms>
</authentication>
But, before you go down that route, I can wholeheartedly recommend checking out the new .NET security features.

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old September 16th, 2006, 11:03 AM
Registered User
 
Join Date: Sep 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Wow, I cannot believe how simple that was. I have been banging my head against the wall on this for the past two days. Thanks so much for the help. Can I ask one more question.

Does the forwarding page know automatically, that it is authenticated? How do I check to see if I am "authenticated" and "logged in". I have used PHP in the past and I would create my own session variables. But ASP.net hides a lot of the code and I do not know what ... if anything ... it passes to the next page.

Any suggestions on this would be greatly appreciated.

Thanks,

Faithful

 
Old September 16th, 2006, 11:13 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Which of the two solutions did you choose?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old September 16th, 2006, 11:42 AM
Registered User
 
Join Date: Sep 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh, I tried both to make sure that it would work and they both did. But I went with your suggestion of the ASP.NET configuration .... creating usernames and passwords in the asp.net database.

 
Old September 16th, 2006, 11:57 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

OK, great.

In code behind, you can see if a user is authenticated with the following code:
Code:
If User.Identity.IsAuthenticated Then

End If
Alternatively, in the markup of a page, you can use controls like the asp:LoginView to distinguish between anonymous and authenticated users.

HtH,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old September 16th, 2006, 12:03 PM
Registered User
 
Join Date: Sep 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Right .... so I just realized that this is the wrong way ... I need to use a access database to do this .... I need to have the users in my database only able to access their own records. So, is this easily done ... and if so how would I have the page push information to the second page like "userID" so that they could only access their own record?

 
Old September 16th, 2006, 01:24 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

By default, only SQL Server is supported out of the box. The following article explains how to use an Access database instead:

http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=404

However, if you're really new to this, you may want to familiarize yourself a bit more with the underlying concepts, before you dig into this.

The MembershipUser class exposes a ProviderUserKey that is the unique ID for the user in the database (a GUID in SQL, an Int in Access). However, Microsoft recommends using a combination of the UserName and the application name instead. See here for more info about the Membershipuser class:

http://msdn2.microsoft.com/en-us/lib...rshipuser.aspx

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
redirect with SSL/cookieless sessions problems jtyson ASP.NET 1.0 and 1.1 Basics 2 May 29th, 2013 07:32 PM
Redirect SKhna ASP.NET 2.0 Basics 1 February 9th, 2008 08:14 AM
Help With PHP ?=name redirect. TheSchwa Beginning PHP 4 September 12th, 2007 02:32 AM
Response.Redirect Problems zanna5910 ASP.NET 1.0 and 1.1 Basics 1 September 30th, 2005 05:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.