Monday, July 10, 2006

C# Blog


We have two tables that are currently in place: comments and posts. Now, the next step is managing the users. In building a multi-user application on .NET we can save ourselves quite a bit of work by utilizing the built-in user management functions.


Master Pages

In Visual Studio we are going to first make use of Master Pages to help take care of some of the redundency in building a website. We can use Master Pages to help with the initial layout.

Multiple master pages can be created for different sections.




A master page is designed with a content place holder which is where code that is specific for each page will go.




Elements placed above or below the content placeholder will remain on consistent throughout.






Using our master page we can place a logo which will stay on every page, our copyright, about us information and a wide variety of other information above or below our content. But wait...Master pages are more powerful than just that. We can create multiple master pages for different sections of our website, allowing us the ability to provide a wide variety of customization. The cascading style sheet is still available, and can be integrated with master pages, allowing even more customization in developing a site.






Role Management

In developing websites the question always comes up as to when a user is added, can we give them different roles? The answer from every developers is yes. The next portion of the discussion goes like something like this "..it would take time to develope such roles, the tables necessary, and code to query the database, and associated discussions" and then the question would be asked can we find a better way?

We don't have to, .NET has taken care of that for us, a .NET developer only has to add the following code to handle displaying a menu if the poster is a user or administrator. We do not want to give the same functionality to a user as we do an administrator, so users will only be able to delete posts on their own blog(s), not others. An administrator on the other hand would be able to delete posts on all blogs (this is needed if content is questionable, such as pornographic material, or just outright inappropriate...you can use your own imagination).

We could therefore use the following code:


if (Roles.IsUserInRole("administrator") == true)
{
deletePostMenu();
}



Let's go through the code. The Roles.IsUserInRole("administrator") is all the code a .NET developer needs to determine the role of a user and grant them appropriate permission.

So in only a few lines of code we have accomplished what would take others many more lines to do, but we as .NET developers have more time to work on other sections of the site.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home