登录后如何重定向到原始URL [英] How to redirect to original URL after login
问题描述
这里我正在开发asp.net中的社交网络应用程序,我正在向所有用户发送一些推荐的个人资料。
所以当用户点击用户名称时我想要的是我的应用程序首先请求登录并在登录后用户将重定向到该特定用户配置文件。
那么如何在asp.net中执行此操作
< u> FormsAuthentication.RedirectFromLoginPage方法(字符串,布尔值)
如果您使用FormsAuthentication Class
[ ^ ],那么它对你来说很简单。
只是尝试实现FormsAuthentication.RedirectFromLoginPage Method
[ ^ ]
Atricles
1. 在ASP.Net中实施表单身份验证 [ ^ ]
2. 如何:实施简单表单身份验证 [ ^ ]
自定义逻辑
如果还没有实现了FormsAuthentication类,然后你必须使用一些自己的自定义逻辑。这可能如下所示。
- >用户请求一些URL,如 www.example.com/MyPage.aspx 。
- >您必须通过会话检查用户是否登录。
- >如果用户是loggenin,那么他/她可以访问,否则您重定向到登录页面,其中ReturnUrl
为QueryString
参数如下所示。
www.example.com/login.aspx?RetutnUrl=MyPage.aspx
And您可以通过HttpContext Class
获取当前页面/请求页面URL(MyPage.aspx)。
参考 - 如何在C#中获取当前页面的URL [ ^ ]
- >在登录页面中,当用户成功登录时,只需获取QueryString
并使用Response.Redirect
重定向到该页面。
Here i am developing social network application in asp.net & i am sending some recommended profiles on all users email ID.
So what i want when user click on users name then first my application will ask for login & after login user will redirect to that particular users profile.
So how to do this in asp.net
FormsAuthentication.RedirectFromLoginPage Method (String, Boolean)
If you are usingFormsAuthentication Class
[^], then it will easy for you.
Just try to implementFormsAuthentication.RedirectFromLoginPage Method
[^]
Atricles
1. Implementing Forms Authentication in ASP.Net[^]
2. How to: Implement Simple Forms Authentication[^]
Custom Logic
If you have not implemented the FormsAuthentication Class, then you have to use some of your own custom logic. That may be like below.
-> User requests some URL like www.example.com/MyPage.aspx.
-> You must be checking whether the user is loggedin or not by Sessions.
-> If user is loggenin, then he/she can access, else you redirect to login page with aReturnUrl
asQueryString
Parameter like below.
www.example.com/login.aspx?RetutnUrl=MyPage.aspx
And you can get the Current Page/Request Page Url (MyPage.aspx) byHttpContext Class
.
Refer - How to get the URL of the current page in C#[^]
-> In login page, when user is successfully loggedin, just fetch theQueryString
and Redirect to that page usingResponse.Redirect
.
这篇关于登录后如何重定向到原始URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!