BlogEngine.Net: Page Level Security

by Xavier Pacheco 23. August 2009 13:17

I needed a way to achieve page-level security for a BlogEngine.net deployment. Brian Carter on his blog provides a pretty good solution with a user control that you simply put on the page you want to secure.  You’ll find it here: BE.N Page Security User Control. One modification I had to make was to the SecurityRole.ascx.cs file. The Page_Load even contains logic to redirect a user to the login page if that user does not belong to the role specified in the user control parameter (see his website for instructions). I simply modified the path to my own page as shown below.

            if (!isInRole) Response.Redirect("~/page/LeaderNot.aspx");
 

Have fun!

Tags:

ASP.NET | .NET | BlogEngine.NET | C#

Swallowing exceptions - it's just sloppy!

by Xavier Pacheco 24. February 2009 02:20

Recently,I was debugging an application and I was having problems with the application simply shutting down unexpectedly. I debugged further and came across the following code:

      
try
{
   System.Diagnostics.Process.Start(Application.StartupPath.ToString() + 
      "\\client_update.exe");
}
catch
{
}
Environment.Exit(0);

This is what we call swallowing exceptions or eating exceptions. Most seasoned developers would agree that this is a bad practice and should not be done. Basically, an exception is raised in the try block and instead of handling it, it is eaten so that the invoking code never knows it happened. To the end user, the application will simply shut down (actually, I added a throw statement in the catch just to see where it would go and it turns out that the exception is still swallowed at the next level - it just got uglier).

If you find yourself having to consider code like this, think more carefully before you do.  There is probably a better way to handle the error. In this case, a test could have been performed to check for the existence of the file and a meaningful error should displayed to the user to allow them to resolve the problem.

Tags: , ,

.NET | Bad Practices | C# | Exception Handling

Anders Hejlsberg and Charlie Calvert discuss the Dynamic Language Runtime (DLR) in C# 4.0

by Xavier Pacheco 19. November 2008 13:24

Here's a very interesting discussion on the Dynamic Language Runtime (DLR) by Anders Hejlsberg and Charlie Calvert from Charlies blog.

http://blogs.msdn.com/charlie/archive/2008/11/13/anders-hejlsberg-video-on-c-dynamic.aspx

I'm going to start looking very closely at C# 4.0, there are some very cool features coming.  Enjoy!

Tags:

Development Tools | Software Development | .NET | C#

This site is Hosted by WebHost4Life

Join WebHost4Life.com

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2012 X Talks Tech