How to display and welcome users to log on in the background

Source: Internet
Author: User

Recently, in background management, we want to implement the welcome user login function. Now, it is not difficult to share with you. It is also a summary of myself. For example, we often see a welcome user in the background of the website, such:

So how can we implement this function? There are many methods. I just say the method I used, because we will use session and cookies for login. All the methods I used are as follows:

I. First, it is explained that when a user logs in, we will store the user information to the session. As to why the user needs to store the information to the session, it is mainly for the convenience of verification judgment and value determination,

2. Write a class to store user information and determine whether the session is empty. If it is not empty, the object is taken out. If it is empty, the user is prompted to log on again.

3. display information by calling a method on the page

The following is a small example:

I. Main Code for storing user classes:

1 using system; 2 using system. collections. generic; 3 using system. LINQ; 4 using system. text; 5 using system. threading. tasks; 6 7 namespace EMS. common 8 {9 using EMS. entity; 10 using system. web; 11 public class userprocess12 {13 /// <summary> 14 // get the current user's object 15 /// </Summary> 16 /// <returns> </returns> 17 public static userinfoentity getuser () 18 {19 // declare a user entity object 20 userinfoentity entity; 21 // judge in session Whether the value of the preceding parameter is null 22 if (httpcontext. Current. session ["uinfo"]! = NULL) 23 {24 // convert the session object to the object 25 entity = (userinfoentity) httpcontext. current. session ["uinfo"]; 26} 27 else28 {29 // jump to the login page and prompt the user to log on to 30 httpcontext again. current. response. redirect ("/admin/login. aspx "); 31 32} 33 // return entity object 34 return entity; 35} 36} 37}

2. on the front-end page, we only need to introduce the namespace, and then call the static method through the class name to get the user's object, and then get the user name through the object point attribute.

The main code for these steps:

1 <% @ import namespace = "EMS. Common" %> 2 3 Welcome [<% = userprocess. getuser (). u_name %>] to log on

Note: you must write an object class, otherwise there will be no u_name. This object class field is best matched with the database, and you are welcome to log on to the label, as for what tags you need! This is because session is used by many enterprises. Other methods may be simpler, but they mainly describe the usage of actual development.

If you have any questions, you can leave a message and provide a better solution!

How to display and welcome users to log on in the background

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.