简体   繁体   中英

Popup window for user login if user has not logged in yet

I have a web applicaiton written in ASP.NET MVC 5. There is to be a landing page in .cshtml. When the user clicks on a button on this page, I am to check whether the user has already logged in (by checking the presence of a specific cookie and its valid value). If the user is already logged in, the landing page should be replaced by the target page. If the user is not logged in yet, a popup window is to be displayed for him to enter his login credentials. If he enters correctly, the login popup window should close, and then the landing page is to be replaced by the target page.

As I don't have prior experience with MVC, I need some help on this. When the user clicks on the button on the landing page, how to send the request to the server to check whether he is already logged in, and only replacing the landing page with the target page if the user is already logged in? Also, if the login popup window is showing, and the user enters a correct credentials, how to replace the landing page with target page?

A simple example would be good.

Thanks in advance.

I am going to attempt to answer this from a higher level instead of provide a generic yet more technical example that is likely going to have to be re-coded to fit your needs.

You will need a boolean variable on your model, lets call it loggedIn. This will represent the logged in state of the user.

  • You want the controller to check the cookies first

  • If the cookie reads that they are logged in then assign loggedIn to true

  • If the cookie reads that they are not logged in then assign loggedIn to false

Once you pass your model to your view, you can then use RAZOR to read the loggedIn boolean. If it is true show the content. If it is false show the partial view for your log in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM