Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

UrlReferrer

Posted on 2006-07-13
11
Medium Priority
?
405 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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.…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

618 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