Solved

UrlReferrer

Posted on 2006-07-13
11
364 Views
Last Modified: 2008-01-09
I have the code below but must have the syntax wrong as it isn't sending the user back to the referring page.  Can anyone help me straighten this out?

Thanks

    protected void Redirect_Refer(object sender, EventArgs e)
    {

        {
            Response.Redirect("Request.UrlReferrer");
        }
       
    }
0
Comment
Question by:pfox74
  • 6
  • 5
11 Comments
 
LVL 12

Expert Comment

by:deanvanrooyen
Comment Utility
where do you want it to go?
0
 

Author Comment

by:pfox74
Comment Utility
to the page it was referred from.  i.e. - A user hits a page they need to login to access.  Once authenticated, I want them to be directed to the referring page and not the default page.

Thanks
0
 
LVL 12

Expert Comment

by:deanvanrooyen
Comment Utility
I see,

are you manualy authenticating or using built in auth eg forms athentication in the web.config -  if forms then use this :

// user authenticated ok now
FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false);  //params   username, persist cookie

web.config eg.
<forms name=".Office" defaultUrl="secure/content/mainportal.aspx" path="/" loginUrl="secure/content/login.aspx" timeout="60" protection="All" slidingExpiration="true">

RedirectFromLoginPage  reads the return url from here
secure/content/login.aspx?ReturnUrl=%2fREO%2fSecure%2fContent%2fpayments.aspx

does this help?
0
 

Author Comment

by:pfox74
Comment Utility
I'm using the built-in login controls.  There is not TextBox1.Text only a login control id=Login1 so I get an error when I use the line of code below.

FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false);
0
 

Author Comment

by:pfox74
Comment Utility
I'm uping the points to 500.  Please help!
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 12

Accepted Solution

by:
deanvanrooyen earned 500 total points
Comment Utility
how are you validating and are you using memberships, I haven done this before but it looks like this could do it


FormsAuthentication.RedirectFromLoginPage(Login1.UserName, Login1.RememberMeSet)
0
 
LVL 12

Expert Comment

by:deanvanrooyen
Comment Utility
hi I just did some checking

the login control property called DestinationPageUrl -  if this is empty then when using form authentication, it uses the forms auth infrastructure for redirecting to the originaly requested page or to the defualturl in the  web.config

are you using forms authentication in the web.config and do you have something set in the Login1.DestinationPageUrl ? this must be empty and using forms auth in web.config

            <authentication mode="Forms">
                  <forms name=".Office" defaultUrl="secure/content/mainportal.aspx" path="/" loginUrl="secure/content/login.aspx" timeout="60" protection="All" slidingExpiration="true">
                  </forms>
            </authentication>
            <authorization>
                  <deny users="?"/>
            </authorization>

hope this all gives you some idea where to check
are you handling the events of the login control manualy?
0
 

Author Comment

by:pfox74
Comment Utility
Ok, that fixed the error I was getting but it still redirects me to the default.aspx page.  I do have authentication mode = "Forms" set and the Login1.DestinationPageUrl is empty.  Any other ideas?  Thanks for the syntax fix.
0
 
LVL 12

Expert Comment

by:deanvanrooyen
Comment Utility
does the url referer actually append onto the query string when you are directed to the login page eg


eg if I got to payments.aspx not logged in I get:
http ...secure/content/login.aspx?ReturnUrl=%2fREO%2fSecure%2fContent%2fpayments.aspx
in the query string... ReturnUrl is the important key is yours there?

please also double confirm you have something in:
defaultUrl
path
loginUrl
protection
in the <forms> section like so
               <forms name=".Office" defaultUrl="secure/content/mainportal.aspx" path="/" loginUrl="secure/content/login.aspx" timeout="60" protection="All" slidingExpiration="true">


thanks

0
 

Author Comment

by:pfox74
Comment Utility
I don't have this part  ?ReturnUrl=%2fREO%2fSecure%2fContent%2fpayments.aspx

I've been doing a server.transfer from the page (see code below).  How do I get the ReturnUrl to display?

 if (User.Identity.IsAuthenticated == false)
        {
           
            Server.Transfer("../.././login.aspx");
        }
0
 
LVL 12

Expert Comment

by:deanvanrooyen
Comment Utility
forms authentication will handle all of this for you automatically, thats why you must make sure it is set up correctly, it is better to use forms auth correctly as if you do your own stuff it leave holes, so please try get it working right, please check your web.config compare it to mine above.

on your query try like so (if it doesnt work try Request.rawurl)  Server.Transfer("../.././login.aspx");

try
        string url = HttpContext.Current.Request.UrlReferrer.ToString();
        Response.Redirect(Server.HtmlDecode("Default2.aspx" + "?ReturnUrl=" + url));
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now