Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
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 February 14th, 2007, 12:14 AM
Friend of Wrox
 
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default execute membership validator after some tasks done

Hello!

I have a standart html text to validate user login under membership class.

The html tag is:
Code:
<asp:LoginView... <asp:ImageButton ID="Submit" runat="server" AlternateText="Login" CommandName="Login" ImageUrl="~/images/go.gif" ValidationGroup="Login" meta:resourcekey="SubmitResource1" />
My problem is that i want to execute some tasks when a user click in the submite button and only when this tasks are maded execute validator login.
My question is:
How can execute this the "Login" command from code-behind?

Thanks!

I have an old application (asp.net 1.1) with users' accounts and I want to check if the current user is an old member, If it is and password match, then encrypte the password and insert it into memberships table then delete this account from old_accounts_Table and only then try to validate user.
So i need to call the login command for perform this last task!

If anyone could help i'll be thankfull!
(Forgive my bad english)



 
Old February 14th, 2007, 12:27 PM
Friend of Wrox
 
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

please... anyone know how can i execute "Login" from code behind ?

 
Old February 14th, 2007, 02:07 PM
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,

I a not sure I understand this:
Quote:
quote:i want to execute some tasks when a user click in the submite button and only when this tasks are maded execute validator login
Are you saying you still want to call normal validation first?

If so, you can handle various events of the Login. For example:

Protected Sub Login1_LoginError(ByVal sender As Object, _
      ByVal e As System.EventArgs) _
      Handles Login1.LoginError

  ' Custom code here

  End Sub

This event fires when authentication fails, so this is a good place to query your old system.

Alternatively, you can use the Membership API. For example:

Membership.ValidateUser(userName, password)

can be used to authenticate a user against the new system while:

Membership.CreateUser(userName, password)

can be used to create a new user.
Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
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 February 14th, 2007, 03:22 PM
Friend of Wrox
 
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It's not that case. I want to execute some tasks BEFORE Validator... Not AFTER!

I think i partially solve the problem:

Code:
<asp:LoginView ID="LoginView1" runat="server">
 <AnonymousTemplate>
   <asp:Login ID="Login1" runat="server" onauthenticate="AuthenticateUser" FailureAction="RedirectToLoginPage" Width="100%" meta:resourcekey="LoginResource1">
    <LayoutTemplate>
      ...

Public Sub AuthenticateUser(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs)

            Dim curLogin As System.Web.UI.WebControls.Login = CType(LoginView1.FindControl("Login1"), System.Web.UI.WebControls.Login)
            Dim txtUsername As TextBox = CType(curLogin.FindControl("UserName"), TextBox)
            Dim txtPassword As TextBox = CType(curLogin.FindControl("Password"), TextBox)
            'my code to see if current user is on old account database.
                'If it is, then pass him to new membership database
            If Membership.ValidateUser(txtUsername.Text, txtPassword.Text) Then


                If Not (Request.QueryString("ReturnUrl")) Is Nothing Then
                    FormsAuthentication.SetAuthCookie(txtUsername.Text, False)
                    Response.Redirect(Request.QueryString("ReturnUrl"))
                Else
                    FormsAuthentication.SetAuthCookie(txtUsername.Text, False)
                    Response.Redirect(HttpContext.Current.Request.Url.AbsolutePath)
                End If
            Else
                FormsAuthentication.RedirectToLoginPage()
            End If
But this store a cooki for this user in cache when the Request.QueryString("ReturnUrl") is nothing

The code is:
FormsAuthentication.SetAuthCookie(txtUsername.Text , False)

So... I don't understand why the system store the cookie! :(

I have a loginView inside a MasterPage
 
Old February 14th, 2007, 03:58 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I am not sure I understand. Aren't you telling it to store a cookie when the QueryString is Nothing?

Also, this:

 If Membership.ValidateUser(txtUsername.Text, txtPassword.Text) Then


is checking against the new Membership system.

I don't see any code that uses the old system.

BTW, Personally, I would run the old code after the new code failed. That way when all users made the switch from old to new, you don't have to modify the code. It will continue to check the new system, but never has to access the old system anymore.
That way, you're favoring new users over old users in terms of performance.

Just a preference though....

Imar
 
Old February 14th, 2007, 08:17 PM
Friend of Wrox
 
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your fast reply!

Quote:
quote:Originally posted by Imar
 I am not sure I understand. Aren't you telling it to store a cookie when the QueryString is Nothing?


Please corrects me if i'm wrong:

If i used:
Code:
FormsAuthentication.SetAuthCookie(txtUsername.Text, False)
I do not save cookie on client machine right?
But When I debug using this code, I make my login, then i close the browser and when I reopen the browser and return to my default page i'm still logged!!

It's that i don't understand!

---------------------------------

Problem 2
Quote:
quote:Originally posted by Imar
 If Membership.ValidateUser(txtUsername.Text, txtPassword.Text) Then
is checking against the new Membership system.
I don't see any code that uses the old system.
BTW, Personally, I would run the old code after the new code failed. That way when all users made the switch from old to new, you don't have to modify the code. It will continue to check the new system, but never has to access the old system anymore.
That way, you're favoring new users over old users in terms of performance.
You don't see the code that uses old system because I didn't wrote it yet! I'll place it before de "membership.validate"
Your idea it's possible and better if i don't want to change my code in future...

But i only have 250 users on my site, and i need that old system because they all have one way password (dashed) with asp.net 1.1

In 3 months I'll erase the code of codebehind and use standart membership because I'll erase the accounts of users that not enter in the system throughout these 3 months.

Thanks very much for your help on this! If you could spend one more minutes to see the problem with "FormsAuthentication.SetAuthCookie" I'll be very greatfull!!

 
Old February 15th, 2007, 05:00 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Maybe this helps:

http://forums.asp.net/thread/1519142.aspx

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
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 February 15th, 2007, 10:07 AM
Friend of Wrox
 
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Imar!

The problem was that i need to close all browser windows to delete the temp cookie!

Problem solved! :)

 
Old February 15th, 2007, 10: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

Ha, great. Glad it's working now....

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
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
Automated tasks in ASP Steve777 Classic ASP Professional 3 June 3rd, 2005 01:52 PM
Too many client tasks pbyers Classic ASP Databases 0 May 3rd, 2005 01:04 AM
conn.execute,command.execute or rs.open vinod_yadav1919 Crystal Reports 0 January 3rd, 2005 10:26 AM
Creating Scheduled Tasks from VB ckrystal VB How-To 0 December 31st, 2004 03:02 PM
Counting Tasks in "Task Report" twsinc Access 1 March 24th, 2004 09:40 AM





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