473,802 Members | 2,172 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.Redirec t("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 FormsAuthentica tion.SetAuthCoo kie of
FormAuthenticat ion.Getredirect Url 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.EventArg s e)
{
bool blnAuthenticati on =
Authenticate(tx tusername.Text, txtpassword.Tex t);
if(blnAuthentic ation)
{

FormsAuthentica tion.RedirectFr omLoginPage(txt username.Text,f alse);
Session["isMemberLogged In"]= true;
Response.Redire ct("index.aspx" );
}
else
{
Session["isMemberLogged In"]= false;
lblErr.Text = "Your Login was invalid. Please try
again.";
}
}

Nov 20 '05 #1
7 11175
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.QueryS tring["ReturnUrl"] != null)
{
Response.Redire ct(Request.Quer yString["ReturnUrl"]);
}
else
{
Response.Redire ct("default.asp x");
}

Nov 20 '05 #2
osh
Also, FormsAuthentica tion.RedirectFr omLoginPage 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
RedirectFromLog inPage 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 FormsAuthentica tion.SetAuthCoo kie (which take the
same parameters as RedirectFromLog inPage I believe) and then do a
Response.Redire ct.

karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"osh" <os******@gmail .com> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.com...
Also, FormsAuthentica tion.RedirectFr omLoginPage 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.Redire ct("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.Redire ct(Reaquest.Que rystring["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.Redire ct("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.Redire ct(Reaquest.Que rystring["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.Redire ct("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.Redire ct(Reaquest.Que rystring["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.QueryS tring["ReturnUrl"] != null)
{
Response.Redire ct(Request.Quer yString["ReturnUrl"]);
}
else
{
Response.Redire ct("default.asp x");
}

to figure out where to redirect...

--
MY ASP.Net tutorials
http://www.openmymind.net/
"savvy" <jo******@gmail .com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.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.Redire ct("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.Redire ct(Reaquest.Que rystring["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
1393
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, will route them to their personally selected default page. Where should I do this, in the Page_Load event of the Default.aspx page? What method does one call to reroute the request?
2
2325
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 running on these servers. There are actually 4 servers that this application has been installed on. The application is a simple ASPX page with a code-behind DLL. The one ASPX page I have is named default.aspx. It uses Windows authentication (anonymous...
3
1349
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 being authenticated, he is to be directed to a special page, instead of the default login page. My approach has been to intercept page requests in Global.Application_BeginRequest(), see which page is being requested, and do either a...
1
2805
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: how can I make user get redirected back to that original page (names "X") which threw him/her to login form? PS: I tried something like getting url name of page X and redirect to login with that name variable. After login, it gets redirected back...
0
810
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 coded like below in my code file protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) { Response.Redirect("DisplayFull.aspx?categoryID=" + TreeView1.SelectedNode.Value );
4
1927
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 page as is currently happening. Curently, they always direct to the Login page in both cases, which i think is confusing.
16
3102
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 and in other browsers please? http://auriance.com/docs/tmp/test.html I'd like the main content and the right menu on the same level. It's working fine in most browsers except in IE7. Do you know how I can fix it?
7
2281
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 the handler for the LoggedIn event of the Login control. The problem is that users don't always go through the Login control. For example, if I check the Remember Me box and then disconnect and then reconnect, I go straight to default.aspx in the...
0
9699
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10304
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7598
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6838
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2966
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.