how can I get a varibale from 2 forms in a project

G

Guest

Hi,

Sorry, maybe it's so simple. but please let me know.

I have Login.aspx.cs taht has a string variable like strUserName.
I have manage.aspx.cs that I want to get strUserName.
How can I do this?

Thank you.
Monica
 
P

Peter Bradley

If you're using Forms Authentication - and it sounds as though you should
be - then you can get the user's credentials from the Identity propery of
the GenericPrincipal object. Look up GenericPrincipal in MSDN and follow
the trail to GenericIdentity for examples of how this works. Basically, the
Name property of the GenericPrincipal's Identity property gives you what you
want.

If you need to roll your own you have several options. The easiest is just
to store the string in the Session:

Session["uid"] = strUserName;

You would do this in some convenient event handler in your Login.aspx page
codebehind - usually in the handler for the submit button, I guess, when
someone logs in.

If you're storing more information about your user than just the user name,
you'll probably want to create an object from a class you define, store the
username in that object (along with whatever else you want to put in there),
and store a reference to that object in the Session.

MyUserObj myuserobj = new MyUserObj();
myuserobj.username = strUserName; // assuming username is a property
Session["MyUserObj"] = myuserobj;

Your object is now globally accessible.

Only your own application model (UML or whatever) will tell you which
strategy is best for your application.

HTH


Peter
 

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