阻止用户直接访问主页
我的应用程序中有 2 个页面:Login.aspx &主页.aspx。
现在,如果用户未登录,他不应该从 Web 浏览器访问 Home.aspx。
我知道这可以通过会话实现,但不知道如何实现。
让我知道该怎么做?
谢谢!
i have 2 pages in my application: Login.aspx & Home.aspx.
Now if user is not login, he should not access the Home.aspx from a web browser.
I know that is possible by session, but don't know how to implement the same.
let me know how to do that?
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道你到底想要什么,但这是一个解决方案
1.成功登录后创建seesion变量,如下
创建会话变量后使用
Server.Transfer()
创建会话变量后,在代码中
方法这是我当前知道如何执行此操作的唯一方法,祝你好运
i don't know exactly what do u want but here is a solution
1. create seesion variable after successful login like this
after u created the session varible make use of
Server.Transfer()
method in your code
That is the only way i know how to do it currently and good luck
我处理此问题的方法是在成功登录时设置令牌。然后在每个页面的加载事件中检查令牌是否已设置。如果没有令牌,它们将被重定向。根据应用程序的性质,我要么将它们发送到未经授权的页面,要么发送到登录屏幕。
通常我将令牌保留在会话中,但如果您希望允许用户在会话之间保持登录状态,那么浏览器 cookie 也应该起作用。
The way I have handled this was to set a token on a successful log in. Then in the load event of each page I check to see if the token is set. If no token they get redirected. Depending on the nature of the app I either send them to a not authorized page or the login screen.
Usually I keep the token in session but if you wanted to allow a user to persist their login across sessions then a browser cookie should work as well.
您可以在登录后使用以下方法创建会话。
请注意,这里该方法不带参数。
现在转到调用主页的 servlet 或 jsp,并使用方法创建另一个会话。
请注意,这里我采用了一个参数
false
,这将阻止用户如果他在登录时尚未创建会话,则意味着他尚未登录。
现在进行检查:
You can create session after login with the method
Note that here this method is without arguments.
Now go to the servlet or jsp which is calling the homepage and create another session there with the method
Note that here I have taken an argument
false
which will prevent the userif he has not created session on login time, meaning he has not logged in.
Now put a check: