Validating and redirecting using a class ...
-
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"); }
-
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"); }
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("");
-
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("");
It is actually a class ... i think i mentioned clearly about it and it inherits from the System.Web.UI.Page ...
-
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"); }