开发者

to display username on all aspx pages

How to Dispaly the username on all aspx pages....?

Can any one help me in this context..开发者_Go百科...

am thinking that by using "session object" we can able to do this...bt am not sure

Can any send the code or links


Assuming that you have a mechanism you can use to obtain the current user's username, you could fetch that and add code to your master page(s) to display the name. There's not really much more that can be said from your question. (Ask a vague question, get a vague answer.)

And also, if you aren't using master pages, you should be using master pages.


You can use a master page if you want to display the username on all pages. Username can be stored in a cookie, session, etc.

Code sample:

lblUsername.Text = Session["Username"]


System.Security.Principal.IPrincipal user;

        user = System.Web.HttpContext.Current.User;

        System.Security.Principal.IIdentity identity;

        identity = user.Identity;

        lblUserName.Text = identity.Name.Substring(identity.Name.IndexOf(@"\") + 1); ToString();


In First Page (Login page), store the value in Session

Session["Username"] = txtusername.text;

And rest of the pages, where you want to display the UserName

lblUser.Text = Session["Username"].Tostring();

For Logout

Session["Username"] = null;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜