Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Based on user redirect to master page is not working


My code login page code as follows



protected void btnsubmit_Click(object sender, EventArgs e)
{

if (txtuser.Text == "admin")
{
Response.Redirect("~/MasterPage4.master");
}
if (txtuser.Text == "Employee")
{
Response.Redirect("~/MasterPage2.master");
}

}

If admin login redirect to masterpage4.master and
if employee login redirect to masterpage2.master.

When i run the above code shows error as follows


This type of page is not served.

what is the mistake in my above code.

What I have tried:

Based on user redirect to master page is not working


My code login page code as follows



protected void btnsubmit_Click(object sender, EventArgs e)
{

if (txtuser.Text == "admin")
{
Response.Redirect("~/MasterPage4.master");
}
if (txtuser.Text == "Employee")
{
Response.Redirect("~/MasterPage2.master");
}

}

If admin login redirect to masterpage4.master and
if employee login redirect to masterpage2.master.

When i run the above code shows error as follows


This type of page is not served.

what is the mistake in my above code.
Posted
Updated 18-Jan-18 22:31pm

You can't redirect to a master page. The master page is simply something that is wrapped around an aspx page, so it is an aspx page you have to redirect to and that page will use your master page.

If you want to have different master pages based on different circumstances then you can specify the master page programmatically but this is generally a bad idea, there are better ways to achieve the same thing.
 
Share this answer
 
Comments
[no name] 19-Jan-18 5:56am    
In master page code as follows

< asp:Menu id="Menu1" runat="server" width="200px" >
< Items >
< asp:MenuItem Text="EMPLOYEE DETAILS" NavigateUrl="~/Employee_Details.aspx"
Value="Employee_Details" >
< /asp:MenuItem >

<asp:MenuItem Text="HR" NavigateUrl="~/HR.aspx" Value="HR">

<asp:MenuItem Text="Manager" NavigateUrl="~/manager.aspx" Value="Manager">

i want to hide the menu based on login page.

i tried this below code in login page

if (!Page.User.IsInRole("Admin"))
{
if (txtUsername.Text == "admin")
{
MenuItem item = NavigationMenu.FindItem("Attendance");
item.Parent.ChildItems.Remove(item);
}
}
shows error as follows

The Navigation menu does not exist in the current context.
[no name] 19-Jan-18 7:37am    
please tell the answer how to solve the above error
F-ES Sitecore 19-Jan-18 9:03am    
That's a completely different issue, you should stick to the thread you created for it.

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