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

S

savvy

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(txtusername.Text,false);
Session["isMemberLoggedIn"]= true;
Response.Redirect("index.aspx");
}
else
{
Session["isMemberLoggedIn"]= false;
lblErr.Text = "Your Login was invalid. Please try
again.";
}
}
 
O

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");
}
 
O

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.
 
K

Karl Seguin

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
 
S

savvy

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
 
S

savvy

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
 
S

savvy

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
 
K

Karl Seguin

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...
 
Joined
Nov 18, 2006
Messages
1
Reaction score
0
How To Redirect To An Ad Page Before Opening The Requested Page

Hi, I am a new member here. I dont know much of javascript. I have a site with lots of downloads. I want that when users click on a link to download, an ad page appears first and after few seconds, it is redirected to the requested page. please help me. I am a layman in such scripts. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top