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

H

Hardy Wang

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.ToString(), 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
 
N

Nicholas Paldino [.NET/C# MVP]

Hardy,

Why pass it around? Why not set a session variable with the information
you need?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top