登录后如何重定向到原始URL [英] How to redirect to original URL after login

查看:393
本文介绍了登录后如何重定向到原始URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我正在开发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 using FormsAuthentication Class[^], then it will easy for you.
Just try to implement FormsAuthentication.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 a ReturnUrl as QueryString Parameter like below.

www.example.com/login.aspx?RetutnUrl=MyPage.aspx


And you can get the Current Page/Request Page Url (MyPage.aspx) by HttpContext Class.
Refer - How to get the URL of the current page in C#[^]

-> In login page, when user is successfully loggedin, just fetch the QueryString and Redirect to that page using Response.Redirect.


这篇关于登录后如何重定向到原始URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆