Hello! I'm new to sitepoint, so I apologize if I'm asking something which has recently been asked.
I am developing a .NET website which I'll describe in Microsoft terms. There is varying content that can be any of the following:
- publicly exposed to unauthenticated users
- viewable by only authorized users
- post-able by users of role A
- deletable by users of roles A & B
I establish this protection by limiting access to pages which expose the above functionality.
All this is fine and dandy in a model that uses various .NET modules - but I'd like to implement this functionality myself. The explanation as to "why" is too long, but to summarize: this is a practice project for me and my team consists of bunch of .NET-skeptical PHP developers that demand all my code be short, concise, and written by me rather than "automagically" generated by Microsoft.
So I've come here to find some people smarter than me to tell me if what I'm doing is legitimate or riddled with flaws! 
Skipping my SQL stuff and login code for now, I have made some code to secure a page from being viewed by the wrong user. My login code verifies username/pw and assigns the user to a UserGroup (analogous to Microsoft "roles"). From there the securing of a page is handled by the following::
Code:
public static class Protection
{
//restricts to a certain usergroup, or if usergroup is "anyone" only checks for login
public static void RestrictTo(UserGroup ugroup)
{
if ((bool)HttpContext.Current.Session["loggedin"] == false)
{
HttpContext.Current.Response.Redirect("~/Login.aspx");
}
else
{
//if its anyone...
if (ugroup == UserGroup.Anyone)
{
//then we do nothing, we're good to go and access is granted
}
//if its a specific user group
else if ((UserGroup)HttpContext.Current.Session["group"] != ugroup)
{
//if they're not that group take them to the root
HttpContext.Current.Response.Redirect("~/");
//todo: maybe take them somewhere else more specific
}
}
}
public enum UserGroup
{
Phpdev,
Netdev,
Administrator,
Anyone
}
}
the above code is then called as follows:
Code:
protected void Page_Load(object sender, EventArgs e)
{
//restricts the page to just admins
Protection.RestrictTo(Protection.UserGroup.Administrator);
}
or
Code:
protected void Page_Load(object sender, EventArgs e)
{
//restricts the page to anyone who is logged in, regardless of UserGroup
//users who are not logged-in will be redirected to login.aspx
Protection.RestrictTo(Protection.UserGroup.Anyone);
}
What do you think? The code appears to do what I want in my test environment, but I'm fairly new to web-programming and would love some feedback. What are some other ways people do what I've done while steering clear of modules/custom modules?
Thanks for reading
Bookmarks