473,499 Members | 1,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to redirect to a requested page instead of default page after login

I able to redirect the user to the index.aspx page after every
successful login, but I dont want certain pages outside the folder to
have a access to general public. So if they click that particular link
or button i want them to be re-directed to the login page and after
successful login i want to them to view the requested page.
Can i redirect the users to the login page using
Reponse.Redirect("js/login.aspx");
in the button click event? or is there any other way?
how we can we get the url so that i can transfer to the respective
page?
I know we should use FormsAuthentication.SetAuthCookie of
FormAuthentication.GetredirectUrl for this purpose but i dont have any
idea how this works.
Any ideas will be greatly appreciated

At the moment i'm using this code

private void btnlogin_Click(object sender, System.EventArgs e)
{
bool blnAuthentication =
Authenticate(txtusername.Text,txtpassword.Text);
if(blnAuthentication)
{

FormsAuthentication.RedirectFromLoginPage(txtusern ame.Text,false);
Session["isMemberLoggedIn"]= true;
Response.Redirect("index.aspx");
}
else
{
Session["isMemberLoggedIn"]= false;
lblErr.Text = "Your Login was invalid. Please try
again.";
}
}

Nov 20 '05 #1
7 11155
osh
When using Forms Authentication, and navigating to a page that requires
authentication should redirect to the login.aspx page (or a page
specified in the <forms loginUrl> tag in the web.config file)... .NET
will automatically append your login.aspx with ?ReturnUrl=[page the
user tried to access un-authenticated]. You could just request this
like so...

if (Request.QueryString["ReturnUrl"] != null)
{
Response.Redirect(Request.QueryString["ReturnUrl"]);
}
else
{
Response.Redirect("default.aspx");
}

Nov 20 '05 #2
osh
Also, FormsAuthentication.RedirectFromLoginPage will redirect to the
default page specified in your <forms defaultUrl> tag in your
web.config file or redirect to the requested page.

Nov 20 '05 #3
RedirectFromLoginPage does 2 things, 1 it sets a cookie and 2 it redirects
(smartly as described by others).

If you want more control over the process, you can do those two steps
yourself.

To set the cookie, youse FormsAuthentication.SetAuthCookie (which take the
same parameters as RedirectFromLoginPage I believe) and then do a
Response.Redirect.

karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"osh" <os******@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
Also, FormsAuthentication.RedirectFromLoginPage will redirect to the
default page specified in your <forms defaultUrl> tag in your
web.config file or redirect to the requested page.

Nov 20 '05 #4
Thanks for all your replies and time
I still got a small problem , it may be silly but
In the button click event i 'm redirecting the page as
Response.Redirect("js/savedjobs.aspx");
when it actually goes to the savedjobs.aspx page its redirected back to
the login.aspx as the member is not logged in. Therefore my URL will be
always pointing to default page.
i'm not able to get the requested page..
I know i'm going wrong somewhere.
Is that the right way redirection ?
How can i grab the required page URL
using Response.Redirect(Reaquest.Querystring["ReturnUrl"]);
Thanks in Advance

Nov 20 '05 #5
Thanks for all your replies and time
I still got a small problem , it may be silly but
In the button click event i 'm redirecting the page as
Response.Redirect("js/savedjobs.aspx");
when it actually goes to the savedjobs.aspx page its redirected back to
the login.aspx as the member is not logged in. Therefore my URL will be
always pointing to default page.
i'm not able to get the requested page..
I know i'm going wrong somewhere.
Is that the right way redirection ?
How can i grab the required page URL
using Response.Redirect(Reaquest.Querystring["ReturnUrl"]);
Thanks in Advance

Nov 20 '05 #6
Thanks for all your replies and time
I still got a small problem , it may be silly but
In the button click event i 'm redirecting the page as
Response.Redirect("js/savedjobs.aspx");
when it actually goes to the savedjobs.aspx page its redirected back to
the login.aspx as the member is not logged in. Therefore my URL will be
always pointing to default page.
i'm not able to get the requested page..
I know i'm going wrong somewhere.
Is that the right way redirection ?
How can i grab the required page URL
using Response.Redirect(Reaquest.Querystring["ReturnUrl"]);
Thanks in Advance

Nov 20 '05 #7
Not sure I understand,
if you take osh's solution and mine and combine it into a super-solution,
things should work.

Use SetAuthCookie and use his code:
if (Request.QueryString["ReturnUrl"] != null)
{
Response.Redirect(Request.QueryString["ReturnUrl"]);
}
else
{
Response.Redirect("default.aspx");
}

to figure out where to redirect...

--
MY ASP.Net tutorials
http://www.openmymind.net/
"savvy" <jo******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Thanks for all your replies and time
I still got a small problem , it may be silly but
In the button click event i 'm redirecting the page as
Response.Redirect("js/savedjobs.aspx");
when it actually goes to the savedjobs.aspx page its redirected back to
the login.aspx as the member is not logged in. Therefore my URL will be
always pointing to default page.
i'm not able to get the requested page..
I know i'm going wrong somewhere.
Is that the right way redirection ?
How can i grab the required page URL
using Response.Redirect(Reaquest.Querystring["ReturnUrl"]);
Thanks in Advance

Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1379
by: paul reed | last post by:
Hi, I use standard form-based authentication. If they haven't logged on yet they get routed to my logon page and all is well. Now, I want to implement a usability feature that after logging in,...
2
2309
by: Michael McGuire | last post by:
I have a very strange problem occurring on a couple of servers I have an ASP.NET application written in C# running on IIS 5.0 with Windows 2000 Server. This is the first ASP.NET application...
3
1334
by: Robert Rotstein | last post by:
I have a homework assignment to create a simple web site and, in certain circumstances, to alter the default sequence of pages displayed -- for instance, if the user attempts to visit a page before...
1
2785
by: vunet.us | last post by:
Imagine: user clicks the link which brings him/her to a secure page (let's call it page "X") which requires login session. If user is not logged in, he/she is redirected to a login page. Question:...
0
792
prabunewindia
by: prabunewindia | last post by:
i have a treeview in one frame(frame1) and a gridview in another(frame2) both frames are in one page when i select a node in tree i want the same page again with sorted data in gridview. i...
4
1910
by: jobs | last post by:
Hello. If my users are logged in, and try to access restricted pages I want to direct them to a custom 403 page. If they are not logged in, I would like to continue to direct them to the login...
16
3080
by: Charles A. Landemaine | last post by:
I set a table with 100% width to occupy all available space, but in IE7 it uses more than that, it uses 100% of the page width instead of 100% of the table container. Could you test the page in IE7...
7
2259
by: Jonathan Wood | last post by:
My site requires all users to log on. Depending on the user's role, they will have access to a certain set of pages. I implemented this by redirecting the user to the appropriate home page in...
0
7131
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5470
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4600
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.