Link to home
Start Free TrialLog in
Avatar of Billy Ma
Billy MaFlag for Hong Kong

asked on

ASP.NET C# Response.Redirect

I don't know why Response.Redirect does not work if I put it in a class?

public static void Check_Variable()
        {
            if (HttpContext.Current.Session["selected_year"] == null)
            {
                Response.Redirect("Option.aspx");
            }

            selected_risk_rating_year = int.Parse(Session["selected_risk_rating_year"].ToString());
        }

any one can help?
ASKER CERTIFIED SOLUTION
Avatar of Praveen Kumar
Praveen Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Billy Ma

ASKER

I tried to do the following

but the sPath always return false....why?

public static void CheckVariable()
        {
            if (HttpContext.Current.Session["selected_year"] == null)
            {
                string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;

                if (sPath == "/Option.aspx")
                {
                    HttpContext.Current.Response.Redirect("Option.aspx");
                }
            }
           
            selected_year = int.Parse(HttpContext.Current.Session["selected_year"].ToString());
        }
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Pratima
Pratima
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
because I put it on the site.master
I however, the Option page also have the site.master
right?
So I have to stop the redirect if it is on the Option page.