locked
Newbe need to set session variable and redirect RRS feed

  • Question

  • User358241827 posted

    Hope someone can help me here:

    i normal use Classic asp but need to create an aspx page to redirect, in asp classic I would have don it like this:

    <%
    Session("Login") = 1

    If request("ref") = 43 Then
    Response.Redirect "vb.aspx"
    End If
    %>

    Need help to translate this to aspx...

    Sunday, April 11, 2021 10:49 AM

All replies

  • User475983607 posted

    The syntax is almost identical.  The difference is ASPX pages has what's known as a code behind file where the page logic is written.  Code blocks still exist in the markup.    I assume your logic goes in the Page_Load event which is fired when the page loads.  

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            Session("Login") = 1
    
            If Request("ref") = 43 Then
                Response.Redirect("vb.aspx")
            End If
    
        End Sub

    Web Forms takes advantage of a events fired in the ASP.NET Page Life Cycle.  It also uses server controls to handle user input and manage state.  I recommend learning ASP.NET Web  Forms fundamentals if you're migrating classic asp to ASP.NET.  You also might consider skipping Web Forms and moving to .NET 5 Razor Pages which is the latest .NET technology stack.  Web Forms is still receives security patches but is no longer receives new updates.

    Sunday, April 11, 2021 12:25 PM
  • User358241827 posted

    I dont have any other pages, do i need a other page to set Page_Load ?

    Can you by any chance write the hole page? the redirect is all this page will do

    Sunday, April 11, 2021 1:18 PM
  • User475983607 posted

    bbbdk

    I dont have any other pages, do i need a other page to set Page_Load ?

    Can you by any chance write the hole page? the redirect is all this page will do

    I provided the code.  There is not much else I can do for you.  You'll need to make an effort to learn Web Forms basics to move forward.  Another option is hiring a developer to help you.

    If you want to continue writing code in the markup then the code almost identical to classic asp.  

    <head runat="server">
        <title></title>
        <%Session("Login") = 1
    
            If Request("ref") = 43 Then
                Response.Redirect("vb.aspx")
            End If %>
    </head>

    Sunday, April 11, 2021 1:32 PM