Hi,

I have 3 pages(Page1, Page2, Page3) in my Application,

Now the problem is that I don't want the User to go directly to Page 2 or Page 3. User should be redirected to Page 1, if they do so.

How this can be achieved?


“There has to be evil so that good can prove its purity above it.”
- Gautam Buddha

Thanx
- Anup

Hi,

I think the quickest way to achieve this is to check for the page referrer on each page or do something with querystrings.

To use the referrer:
Request.UrlReferrer

On the pages where a specific page has to have been visited first, check for the name of the referring page and create an if statement to process the result (ie. if there is no referrer then bounce back to page 1)

If you can let me know which language you are using I will create example code for you.

Regards,

Hi,

I think the quickest way to achieve this is to check for the page referrer on each page or do something with querystrings.

To use the referrer:
Request.UrlReferrer

On the pages where a specific page has to have been visited first, check for the name of the referring page and create an if statement to process the result (ie. if there is no referrer then bounce back to page 1)

If you can let me know which language you are using I will create example code for you.

Regards,

Hi,

I am using vb.Net.

Thanx for helping..
Anup

you can even make use of sessions too...

create a session on first page & on the 2nd n 3rd page check if any session exist or not. if session does not exist redirect user to 1st page...

or

create a session variable on first page (may be on your submit button), n on 2nd n 3rd page, check if the session's value is empty or not. if its empty, redirect it to 1st page else, allow the user to work on that page..

if ur flow is like 1st-2nd-3rd, then create a session var on 1st page's submit button
for ex,

Session["Temp"]="True";

on 2nd page page check if session is null

if(Session["Temp"]==null)
{
Response.Redirect("1st page.aspx");
}
else
{
//your code for 2nd page
}

same as for 2nd n 3rd page's submit button..

& on 3rd page, if clear the session with session.abandon() if you want.

hope it helps.

Hi,

The session variable route is another valid way. Personally I would not use this as your storing information in sessionstate that doesnt really need to be there - sessions also time out so I would advise using some kind of sessionwrapper class if you were to go that way.

I have included the code for each of your pages if you want to use the referrer option. Basically put this section of code into the pageload of any of your pages that you need to check. The first variable "correctReferringPage" is the page name that you are checking for - this script will automatically redirect them to the right place if they have missed a hop.

Hope it helps :)

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        'Set the correct page name you are looking for
        Dim correctReferringPage As String = "Page1.aspx"

        'declare a variable and check for a referring page object
        Dim myReferreringPage As String = ""

        If Not Page.Request.UrlReferrer Is Nothing Then
            myReferreringPage = Request.UrlReferrer.ToString()
        End If

        If myReferreringPage = String.Empty Then
            'if the referrer is empty then send them back to the page they SHOULD have come from
            Response.Redirect(correctReferringPage)
        Else
            'Split the querystring into a 1 dimensional array
            Dim URLSplit As String() = myReferreringPage.Split("/")
            'check the last index of the array (which will be the page name (page1.aspx etc)
            If URLSplit(URLSplit.Length - 1).ToString() <> correctReferringPage Then
                Response.Redirect(correctReferringPage)
            End If
        End If
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.