More on the ASP.NET Development
The site started using a pre-designed open source website template called MultiFlex 3. I had all the css/html and it had a nice menu. So I dissected all of the menu elements html, created a menu class and basically put the menu together in a StringBuilder. Also the menu included code to check that the user was logged in and if a logged in user was a Site Admin. The two methods below show how to do this this.
public bool IsLoggedIn() {
return (HttpContext.Current.User.Identity.IsAuthenticated) ;
}
public bool IsSiteAdmin()
{
return (IsLoggedIn() && HttpContext.Current.User.IsInRole
("Site Admin")) ;
}
This allows access to the all important Admin pages to be restricted by having this in the Page_Load event. below (This is the code that runs when the page has loaded).
protected void Page_Load(object sender, EventArgs e)
{
menus m= new menus() ;
if (!m.IsSiteAdmin())
{
Response.Redirect("sign-in.aspx") ;
}
}
If you're not a Site Administrator this redirects you to the sign-in page. Arguably it should redirect unauthenticated users there and authenticated non-Admins elsewhere. I'll add that in...
- Link to What is ASP.NET? article
- Link to C# Tutorials


No comments yet. Leave a Comment