471,319 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

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 10932
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by paul reed | last post: by
2 posts views Thread by Michael McGuire | last post: by
3 posts views Thread by Robert Rotstein | last post: by
16 posts views Thread by Charles A. Landemaine | last post: by
7 posts views Thread by Jonathan Wood | last post: by
reply views Thread by rosydwin | last post: by

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.