I am sure that you have faced a scenario where you need to redirect a user based on his role. There can be many methods of redirection here I am mentioning one of them.

What I did is put the name of the role and the redirection url in the web.config file. Some thing like this:

    <add key="Admin" value="Admin/AdminHomePage.aspx"/>
        <
add key="Teacher" value="Teachers/TeacherHomePage.aspx"/>
        <
add key="Student" value="Students/StudentHomePage.aspx"/>
        <
add key="ErrorPage" value="ErrorPage.aspx"/>

And now in the base page I will have a method that will return the redirection url.

 if (role != null && role.Length > 0)
        {
            
if (role.Equals("Admin"))
                
return (string)ConfigurationManager.AppSettings["Admin"];
            
else if (role.Equals("Teacher"))
                
return (string)ConfigurationManager.AppSettings["Teacher"];
            
else if (role.Equals("Student"))
                
return (string)ConfigurationManager.AppSettings["Student"];
            
else return (string)ConfigurationManager.AppSettings["ErrorPage"]; 
        }

If you see the above code you will notice the big problem. And the problem is that whenever you have to add new role you will write few more lines of code and hence have to build the application.

You can simply achieve this in lesser lines of code:

 if (role != null && role.Length > 0)
        {
            
return (string)ConfigurationManager.AppSettings[role]; 
        }
        
else return (string)ConfigurationManager.AppSettings["ErrorPage"];

Now if later you add a new role you only need to add in the web.config file and hence not build the application. Although the application will restart once the web.config file is altered.

powered by IMHO 1.3