• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 469
  • Last Modified:

URI Referrer: How can I redirect to another page based on referring URL?

How can I limit visibility and access to a form confirmation page?

I have a form that inserts a record into the database then displays a separate confirmation page saying thanks.  The page does the insert, then uses response.redirect to display the thank you page.  I would like to make it so someone just could not print the thank you page by typing in the url.  How could I make it so that if they type in the url, they go back to the homepage, but, if it is a result of a successful form insert, they see it after the insert is done?

public void PreLoad(object sender, EventArgs e)
    {
        Uri Referrer = Request.UrlReferrer;
 
        if ((Referrer != null) || (!Referrer.ToString.Equals("default.aspx")))
        {
            Response.Redirect("http://www.yahoo.com");
        }

Open in new window

0
devnewbee
Asked:
devnewbee
  • 2
2 Solutions
 
jmwheelerCommented:
Instead of using the referrer why not use a session variable to determine if they should have access.  In the code that does the insert add code like below:

//Code to insert record here
Session["FormInserted"] = true;
Response.Redirect("~/confirmation.aspx");

Then in the page load for the confirmation check

if (!IsPostBack && Session["FormInserted"] == null)
       Response.Redirect("~/default.aspx");
else
       Session.Remove("FormInserted");
0
 
abelCommented:
You are quite close. Use:

string referrerPath = Request.UrlReferrer.GetLeftPart(UriPartial.Path);if(referrerPath.EndsWith("default.aspx")) {    ...}
instead and you should be fine
0
 
abelCommented:
but sessions are a much better idea, as jmwheeler points out :)
0
 
devnewbeeAuthor Commented:
Thanks you guys.  The assistance here is phenomenal.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now