Search code examples
c#asp.nethttp-redirectradiobuttonlist

Redirecting to page from radio button selection


I'm creating multiple pages wherein at the first page consists of 2 radiobuttonlist having values admin and customer. Now after the user selects any of the two options, the page is redirected a login.aspx page, where the user has to enter the id and password. After it's authentication, I want the user to be redirected to different pages according to the selection made on radiobutton.

For eg. on selecting admin, I want the user to be redirected on page abc.aspx, while if the selection is customer, the it should be redirected to page efg.aspx.

Is it possible?


Solution

  • Yes, of course. This is something that you can achieve storing the radio button selection into some cookie for later send it with the authentication HTTP request.

    Once user is authenticated, just read the whole cookie and redirect to the desired page.

    For example:

    string virtualPath = null;
    
    switch(HttpContext.Current.Request.Cookies["UserRole"].Value)
    {
          case "Admin":
               virtualPath = "~/admin.aspx";
               break;
    
          case "RegularUser"
               virtualPath = "~/user.aspx";
               break;
    }
    
    HttpContext.Current.Response.Redirect(virtualPath);