Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Validating and redirecting using a class ...

Validating and redirecting using a class ...

Scheduled Pinned Locked Moved ASP.NET
designhelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rahman Mahmoodi
    wrote on last edited by
    #1

    hello guys, Just I was wondering why this code doesn't work. Basically, i have a class that inhirits from the System.web.ui.page ... just I am checking if the session is valid and if yes I redirect user to page requested else to the login page. However it raises error : Exception Details: System.Web.HttpException: Response is not available in this context. Source Error: Line 25: Response.Redirect(pageToVisit); Line 26: else Line 27: Response.Redirect("Login.aspx"); Line 28: } Line 29: My class is as below: using System; using System.Web; using System.Web.SessionState; using System.Web.UI; namespace MobileShop { /// /// Summary description for CheckLogin. /// public class CheckLogin: System.Web.UI.Page { } public void CheckLogins(string pageToVisit) { if (Session["Authenticated"]=="yes") Response.Redirect(pageToVisit); else Response.Redirect("Login.aspx"); }

    A M 2 Replies Last reply
    0
    • R Rahman Mahmoodi

      hello guys, Just I was wondering why this code doesn't work. Basically, i have a class that inhirits from the System.web.ui.page ... just I am checking if the session is valid and if yes I redirect user to page requested else to the login page. However it raises error : Exception Details: System.Web.HttpException: Response is not available in this context. Source Error: Line 25: Response.Redirect(pageToVisit); Line 26: else Line 27: Response.Redirect("Login.aspx"); Line 28: } Line 29: My class is as below: using System; using System.Web; using System.Web.SessionState; using System.Web.UI; namespace MobileShop { /// /// Summary description for CheckLogin. /// public class CheckLogin: System.Web.UI.Page { } public void CheckLogins(string pageToVisit) { if (Session["Authenticated"]=="yes") Response.Redirect(pageToVisit); else Response.Redirect("Login.aspx"); }

      A Offline
      A Offline
      Anzy
      wrote on last edited by
      #2

      Is your CheckLogin just a class or a website (ie. is it a .aspx.cs file?) From the exception you are getting it seems CheckLogin is not a website and hence it explains why you cannot use Page.Response.Redirect(). I've never tried this before and not sure if this is the best option, but you might want to consider using something like this: System.Web.HttpResponse x = new HttpResponse(); x.Redirect("");

      R 1 Reply Last reply
      0
      • A Anzy

        Is your CheckLogin just a class or a website (ie. is it a .aspx.cs file?) From the exception you are getting it seems CheckLogin is not a website and hence it explains why you cannot use Page.Response.Redirect(). I've never tried this before and not sure if this is the best option, but you might want to consider using something like this: System.Web.HttpResponse x = new HttpResponse(); x.Redirect("");

        R Offline
        R Offline
        Rahman Mahmoodi
        wrote on last edited by
        #3

        It is actually a class ... i think i mentioned clearly about it and it inherits from the System.Web.UI.Page ...

        1 Reply Last reply
        0
        • R Rahman Mahmoodi

          hello guys, Just I was wondering why this code doesn't work. Basically, i have a class that inhirits from the System.web.ui.page ... just I am checking if the session is valid and if yes I redirect user to page requested else to the login page. However it raises error : Exception Details: System.Web.HttpException: Response is not available in this context. Source Error: Line 25: Response.Redirect(pageToVisit); Line 26: else Line 27: Response.Redirect("Login.aspx"); Line 28: } Line 29: My class is as below: using System; using System.Web; using System.Web.SessionState; using System.Web.UI; namespace MobileShop { /// /// Summary description for CheckLogin. /// public class CheckLogin: System.Web.UI.Page { } public void CheckLogins(string pageToVisit) { if (Session["Authenticated"]=="yes") Response.Redirect(pageToVisit); else Response.Redirect("Login.aspx"); }

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          Hi there, When/how do you use the CheckLogins method? Make sure that you only use the Response object in the context where it is available.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups