简体   繁体   English

如果用户尚未登录,则用于用户登录的弹出窗口

[英]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.我有一个用 ASP.NET MVC 5 编写的 Web 应用程序。在 .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).当用户单击此页面上的按钮时,我将检查用户是否已经登录(通过检查特定 cookie 的存在及其有效值)。 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.由于我之前没有使用 MVC 的经验,因此我需要一些帮助。 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.你的模型需要一个布尔变量,我们称之为loggedIn。 This will represent the logged in state of the user.这将代表用户的登录状态。

  • You want the controller to check the cookies first您希望控制器首先检查 cookie

  • If the cookie reads that they are logged in then assign loggedIn to true如果 cookie 读取他们已登录,则将 loginedIn 分配为 true

  • If the cookie reads that they are not logged in then assign loggedIn to false如果 cookie 读取他们未登录,则将 loginedIn 分配为 false

Once you pass your model to your view, you can then use RAZOR to read the loggedIn boolean.将模型传递给视图后,您就可以使用 RAZOR 读取登录布尔值。 If it is true show the content.如果是真的显示内容。 If it is false show the partial view for your log in.如果为 false,则显示登录的部分视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果用户尚未登录Angular JS,则重定向到登录页面 - Redirect to a login page if the user is not yet logged in Angular JS 如何保持用户使用弹出窗口登录? - How do you keep a user logged in with a popup window? 如果用户未登录,rails jquery弹出窗口 - rails jquery popup if user not logged in React - 用户登录后如何在导航栏中隐藏注册/登录? - React - How to hide register/login in navbar once a user has logged in? 如果用户已登录FB,如何阻止我的Facebook登录弹出窗口出现? - How do I stop my Facebook login popup from appearing if user is already logged into FB? 未登录用户的“登录”值和已登录用户的“注销”值 - 'Login' value for non logged user and 'Log Out' value for logged in user 如果用户未登录,“邀请朋友”弹出窗口会出现问题 - Invite friends popup is struggling, if the user is not logged in 区分未登录的Facebook用户与已登录的Facebook用户,但尚未授权我们的应用程序 - Differentiate a not-logged-in Facebook user vs. a logged-in Facebook user but not authorize our application yet 限制用户登录后重定向到登录页面,即使他按角度按浏览器的后退按钮? - restrict the redirection to login page once the user has already logged in even if he press the back button of browser in angular? 仅当用户未登录时才显示登录屏幕 - Show login screen only if user is not logged in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM