471,627 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Pass UserID instead of Username to other pages after logged on, ASP.NET 2.0

Hi,
I have my own user table with definition like

UserID int not null primary key,
Username varchar(50) not null,
Password varchar(50) not null,
Firstname varchar(50) not null,
Lastname varchar(50) not null,
Email varchar(50) not null,
......

I create my own Membership provider to inherit SqlMembershipProvider

public class MyMembershipProvider :
System.Web.Security.SqlMembershipProvider {
public MyMembershipProvider() {
}

public override bool ValidateUser(string username, string password) {
// query my DB to verify user
MyUser mu = new MyUser();
return mu.VerifyUser(username, password);
}
}

In Asp.Net 1.1, we can use
FormsAuthentication.RedirectFromLoginPage(UserID.T oString(), false); to save
UserID (which is whatever I return from my own function, including UserID
from User table). Later on, we just call User.Identity.Name to retrieve the
UserID and it could be used as I like.

But in ASP.NET 2.0, I just need to add

<membership defaultProvider="MyMembershipProvider">
<providers>
<add name="MyMembershipProvider"
type="MyMembershipProvider"/>
</providers>
</membership>

to my web.config file, it will handle authentication autimatically. In this
case how can I pass UserID instead of username to other pages?
Thanks
Hardy
Dec 4 '05 #1
1 2158
Hardy,

Why pass it around? Why not set a session variable with the information
you need?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Hardy Wang" <ha*******@hotmail.com> wrote in message
news:um****************@TK2MSFTNGP12.phx.gbl...
Hi,
I have my own user table with definition like

UserID int not null primary key,
Username varchar(50) not null,
Password varchar(50) not null,
Firstname varchar(50) not null,
Lastname varchar(50) not null,
Email varchar(50) not null,
.....

I create my own Membership provider to inherit SqlMembershipProvider

public class MyMembershipProvider :
System.Web.Security.SqlMembershipProvider {
public MyMembershipProvider() {
}

public override bool ValidateUser(string username, string password) {
// query my DB to verify user
MyUser mu = new MyUser();
return mu.VerifyUser(username, password);
}
}

In Asp.Net 1.1, we can use
FormsAuthentication.RedirectFromLoginPage(UserID.T oString(), false); to
save UserID (which is whatever I return from my own function, including
UserID from User table). Later on, we just call User.Identity.Name to
retrieve the UserID and it could be used as I like.

But in ASP.NET 2.0, I just need to add

<membership defaultProvider="MyMembershipProvider">
<providers>
<add name="MyMembershipProvider"
type="MyMembershipProvider"/>
</providers>
</membership>

to my web.config file, it will handle authentication autimatically. In
this case how can I pass UserID instead of username to other pages?
Thanks
Hardy

Dec 5 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by sileesh | last post: by
4 posts views Thread by James | last post: by
11 posts views Thread by Helmut Jarausch | last post: by
2 posts views Thread by ThatsIT.net.au | last post: by
reply views Thread by leo001 | last post: by

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.