Solved

UrlReferrer

Posted on 2006-07-13
11
401 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Independent Software Vendors: 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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

696 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