如果用户有身份验证 cookie,则重定向到默认页面
我的asp.net登录页面中有以下代码:
if (Request.QueryString["ReturnUrl"] != null)
FormsAuthentication.RedirectFromLoginPage(UserLogin.UserName, UserLogin.RememberMeSet);
else
FormsAuthentication.SetAuthCookie(UserLogin.UserName, UserLogin.RememberMeSet);
我想要的场景是:
当用户进入登录页面时,将检查他是否有身份验证cookie,如果有,则自动重定向到默认页面(这是一个只有经过身份验证的用户才能看到的页面)。
如何才能实现这一目标?
I have the following code in my asp.net login page:
if (Request.QueryString["ReturnUrl"] != null)
FormsAuthentication.RedirectFromLoginPage(UserLogin.UserName, UserLogin.RememberMeSet);
else
FormsAuthentication.SetAuthCookie(UserLogin.UserName, UserLogin.RememberMeSet);
The scenario I want is:
when the user enters the login page, it will be checked if he has an authentication cookie, and if so, he is automatically redirected to the default page (which is a page that only authenticated users can see).
How can this be achieved ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
例如,将其放在 Page_Init 中...
如果用户登录,它只会将用户弹回目的地。
Place this in the Page_Init for example...
It'll just bounce the user onwards to the destination if they're logged in.
如果身份验证 cookie 存在并且有效,则上下文将填充用户数据。只需检查是否:
If the authentication cookie is present and it is valid, the context will be populated with the user data. Just check then if: