?
Solved

UrlReferrer

Posted on 2006-07-13
11
Medium Priority
?
402 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 1500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

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