Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,


My website within ASP.NET 2012 development phase has three roles(Admin,Members,Organisation) .I have implemented each folder with appropriate web config security restrictions .My problem is after implementing redirection based on user roles within LogIn.cs .An error is thrown about a default page non existing within my project hierarchy, and I don't have any default page created in my project ,but homepage set as start.

What I did and tried to remedy the situation was to create an empty default page inheriting from the Master Page .Upon testing user roles the default page is returned with LoginName and not directed as implemented in loginIn.cs.


I would be very grateful for any assistance rendered .Many thanks in advance.


This my Login.cs

C#
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        {
            bool isAdministrator = Roles.IsUserInRole(User.Identity.Name, "Administrator");
            bool isMembers= Roles.IsUserInRole(User.Identity.Name, "Members");


            //if User is an admin, send to admin homepage, otherwise to account home page
            if (isAdministrator)
                Response.Redirect("~/Admin/SiteAdmin.aspx");
            else if (isMembers)
                Response.Redirect("~/Members/Dashboard.aspx");
        }
    }

}
Posted
Updated 28-Jul-15 9:03am
v4
Comments
Aravindba 28-Jul-15 22:01pm    
your code is right,u sure u have Admin and Members folders inside root folder(ur website folder) ? Clear browser cache , try to run SiteAdmin.aspx directly
Layman22 29-Jul-15 2:34am    
Aravindba,I have applied your recommendations .Individual pages when executed separately are displaying without any problems and all folders are within the website folder .

Unfortunately the problem still persists as I cannot redirect users in respect of their roles.
Layman22 29-Jul-15 2:54am    
I have applied the button and still the problem persists.
Aravindba 29-Jul-15 3:11am    
can u show what u write in page load event in siteAdmin.aspx and Dashboard.aspx page ?

and

Add 2 new forms and pass that form name in login page load event

if (isAdministrator)
Response.Redirect("~/Admin/Default.aspx");
else (isMembers)
Response.Redirect("~/Members/Default2.aspx");

Dont write any code in page load event of Default1 and Default2
Default1 add in Admin folder and Default2 add in Members folder
Layman22 29-Jul-15 3:18am    
They are both empty and namespace Ling is highlighted in red within these pages .

1 solution

In login page load event u write code ? that is correct ? in login page load even u get
C#
bool isAdministrator = Roles.IsUserInRole(User.Identity.Name, "Administrator");
bool isMembers= Roles.IsUserInRole(User.Identity.Name, "Members");

or in button click u get ?

Try like this,remove if form else part,i mean if and else ,

C#
if (isAdministrator)
Response.Redirect("~/Admin/SiteAdmin.aspx");
else (isMembers)
Response.Redirect("~/Members/Dashboard.aspx");


or try like this,put one button,in that button click even u write that code and check.

or

in login page load event u write this code only and check

Response.Redirect("~/Admin/SiteAdmin.aspx");
 
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