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
.