Click here to Skip to main content
15,915,509 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I can able to hide/show the buttons of a webpage according to the user login role. but how will i hide the whole aspx page when the userlogin.
Posted
Comments
Bh@gyesh 19-Apr-14 1:39am    
Hi,
If I understood correctly your question, then you want redirection of different page depending upon role?
if yes, then you can do as following.
if (role='admin')
Response.Redirect("Page1.aspx");
else
Response.Redirect("Page2.aspx");
Member 10578683 19-Apr-14 2:03am    
No No i want to hide or show an aspx page.
I am giving u an example.In this case i am hide/show a button. similarly how will i make visible/hide a aspx page
if (Session["Role"] != null && !string.IsNullOrEmpty(Session["Role"].ToString()))
{
con.Open();
using (SqlCommand comm = new SqlCommand("select [Add] from Role1 where Role_Name=@Role and Pages=@Pages", con))
{
string Role = (string)(Session["Role"]);
// 2. define parameters used in command object
SqlParameter para = null;
para = new SqlParameter();
para.ParameterName = "@Role";
para.Value = Role;
comm.Parameters.Add(para);

//Pass @Pages parameter
para = new SqlParameter();
para.ParameterName = "@Pages";
para.Value = "Checkin";
comm.Parameters.Add(para);
SqlDataReader reade = comm.ExecuteReader();
while (reade.Read())
{
Session["Add"] = Convert.ToString(reade["Add"]);
}
//Button Add = (Button)PreviousPage.FindControl("Button2");
if (Session["Add"].ToString() == "Y")
{
Button2.Visible = true;
}
else
{
Button2.Visible = false;

}
con.Close();

} //con.Open
Bh@gyesh 19-Apr-14 2:26am    
I am not getting your question. Can you please state scenario why you want this?
Member 10578683 19-Apr-14 7:47am    
When the database contain Y in view field then a user who login can view the abc.aspx page. for that i need
syed shanu 20-Apr-14 22:06pm    
That is what Bh@gyesh said .you can redirect depend on the user role and if (Session["Add"].ToString() == "Y") { redirect to abc.aspx} else { some other page }This is one method.or with in ac.aspx page place TR or Div or panel or etc and place all your controls which should be hidden.
if (Session["Add"].ToString() == "Y") { Div.visible=false} else { div.visible=true }

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