Solved

UrlReferrer

Posted on 2006-07-13
11
386 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
ID: 17102524
where do you want it to go?
0
 

Author Comment

by:pfox74
ID: 17102574
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
ID: 17103438
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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:pfox74
ID: 17103576
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
ID: 17103957
I'm uping the points to 500.  Please help!
0
 
LVL 12

Accepted Solution

by:
deanvanrooyen earned 500 total points
ID: 17104243
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
ID: 17104333
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
ID: 17104585
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
ID: 17105143
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
ID: 17109826
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
ID: 17110951
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 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