Click here to Skip to main content
15,909,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public static SqlConnection OpenConnection()
        {
            try
            {
                if (HttpContext.Current.Session["DATABASE"] != null && HttpContext.Current.Session["USERNAME"] != null && HttpContext.Current.Session["PASSWORD"] != null && HttpContext.Current.Session["SERVERNAME"] != null)
                {
                    cn = new SqlConnection("uid=" + HttpContext.Current.Session["USERNAME"].ToString() + ";pwd=" + HttpContext.Current.Session["PASSWORD"].ToString() + ";server=" + HttpContext.Current.Session["SERVERNAME"].ToString() + ";database=" + HttpContext.Current.Session["DATABASE"].ToString() + "");
                    if (cn.State == ConnectionState.Closed)
                    {
                        cn.Open();
                    }

                }
                else
                {
                    HttpContext.Current.Response.Redirect("~/Login.aspx");

                }
                return cn;

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }



But, my Login.aspx is in Folder Admin.....
what should be the code for it?
Posted
Comments
Amol Jadhao 14-Mar-14 4:09am    
put a folder name precedence such as HttpContext.Current.Response.Redirect("~/Admin/Login.aspx");
Raajkumar.b 15-Mar-14 2:55am    
check this link
http://forums.asp.net/t/1666153.aspx?How+to+use+the+response+redirect+method+in+class+file

use if it is in root directory.
C#
HttpContext.Current.Response.Redirect("~/Login.aspx"),


AND if it is inside any directory, then use directory name like,

C#
HttpContext.Current.Response.Redirect("~/Admin/Login.aspx")
 
Share this answer
 
v4
Comments
Aravindba 14-Mar-14 5:12am    
5+
Pranav-BiTwiser 14-Mar-14 7:08am    
its not working....
HttpContext.Current.Response.Redirect(@"Admin\Login.aspx");


Try this. Its redirecting to Login.aspx. Forms are in local right. So use \ instead of /.
Also add this (Optional)
Response.Flush();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900