Please forum, I really need help on this
Following my inability to succeed in redirecting Admin to Admin page in my project using forms authentication and authorization, I decided to make some changes. However, it is only Admin that does not gets redirected, other users gets redirected to their respective pages based on their roles.
I discovered that Admin gets redirected to adminpage when I did not use RoleId in Users table as foreign key to the RoleId in the RoleTable.
So, with this, I created a new web application project, still with my existing codes and forms authentication, but this time I added two folders (Admin and Users) that will hold some web config and page files.
Inside the Admin folder, there are two aspx files (adminpage and adminreg) and a web config file. The adminpage is the page where an admin can navigate to other pages like adminreg. While adminreg is a page where a senior admin can add an admin staff to oversee some activities as an admin.
In the Users folder, there is one aspx file and a web config file.
Other pages like Login, Signup, Default are in the root directory.
When any user (admin or user) browses the application, the default page will start first. On the Default page you can click on either Login if you want to login or Signup if your are a new user. However, a senior already has his login details in the database, so the Signup page is really for other users.
So, when an Admin login, it will redirect Admin to adminpage and also if users login, it will redirect them to Userspage.
But the issue I have is that when I try to view adminpage inside the Admin folder by right-clicking on the adminpage file and view in browser, I get the below error.
Or when admin or users login and they are redirected to their respective pages, I copied the address of the respective pages in the browser tab and logged out. After a while I open my browser and paste the address and clicked enter, then I saw this error in the page load event of the respective pages.
But I thought it should have redirected any user to Login, it did not instead it gave me this error. What should I do?
{
if (this.Page.User.Identity.IsAuthenticated)
{
//this is where the error normally shows.
lblMessage.Text = Session["user"].ToString();
Showdata1();
Showdata();
}
else
{
//it is supposed to redirect to Login if user is not authenticated, but it did not.
Response.Redirect("Login.aspx");
}
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();
Response.AppendHeader("Pragma", "no-cache");
}