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: