MVC Application Implementation Member login function

Source: Internet
Author: User

Before implementation, we have verified the success of the information in the cookie in the "MVC login ready to write a good cookie" http://www.cnblogs.com/insus/p/3464105.html. Real authentication and login is now possible.

First go to the database, write a login certificate stored procedure [dbo]. [Usp_member_loginverifyandgetinfo]:


The stored procedure has two judgments, the user enters a nonexistent account, also must prompt the account number or the password error, for the system security consideration, generally does not suggest separately prompts.

To go to the application, locate the entities directory, modify the MemberEntity.cs category, and add a method:

Then go to the controller and add a loginverify () to the ActionResult:


After success, the two cookie values need to be modified and assigned, the IsLogin set to True, and the username are assigned together. The latter is after logging in, displaying the currently logged in user name.

Next, we go to find the views/member/index.cshtml view, add a form, two text boxes, and an ammonium button:


Write the jquery code that logs in the Ammonium button:



OK, if the login verification passes, it will certainly guide the/member/default view.

Now there is a problem, need to think of, is the validation passed, the user if still open the/member/index view, when it is still showing the login status, clearly logged in successfully, such as the display of this view, there seems to be a little bit inadequate.

Now insus.net solve it. Open controller MemberController.cs in index ActionResult, you need to add a cookie,




In the default view, the login user name is displayed:



Live action Demo:

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.