Wednesday, September 26, 2007

Generate Random SQL Data

If you ever need random data for your SQL tables, be sure to check out http://www.generatedata.com/. Their random data generator generates transact SQL scripts that you can run to insert random data into your database. Other export formats are also available.

Tuesday, September 18, 2007

ASP.NET Login Control Remember Me Doesn't Work

I recently did a quick Google search for an issue I was having with the ASP.NET login control where the Remember Me feature of the control appeared not to be working as I had expected. I found a few hits on Google Groups where users were experiencing the exact same symptom, but nobody was getting an answer to their question.

First of all, I knew that the login control called the FormsAuthentication.SetAuthCookie() method to save the cookie, so I figured it must have something to do with the cookie expiring sooner than I wanted. Knowing that, I looked at the details of the cookie and noticed that it was set to expire 30 minutes in the future. So I did another quick Google search and found a great article on Forms Authentication. Sure enough, there is a section in web.config that is used to configure the authentication cookie, one of which is the timeout. I'd recommend reading that article, first, but this is the authentication section from my web.config with the cookie timeout configured for 30 days.

<authentication mode="Forms">
<forms
loginUrl="Login/Login.aspx"
name=".ASPXFORMSAUTH"
protection="All"
timeout="43200"
requireSSL="false"
slidingExpiration="true"
cookieless="UseCookies"
enableCrossAppRedirects="false"
/>
</authentication>


Hope that helps...

Tuesday, August 28, 2007

Comparing the Timer Classes in .NET

A few days ago, I ran into some issues with the timer that I was using in my Windows Service. As it turns out, not all timers in .NET are created equal. This article was able to give me some valuable insight that I was able to use to solve my problem.

Friday, August 17, 2007

How To: Disable Clear Type for Office 2007

It could be that I have something wrong with my eyes, but the ClearType fonts that Microsoft now uses for its new Office 2007 suite is incredibly painful to my eyes. If you would like to disable ClearType fonts in Office 2007 and/or have Office respect system settings, try the following:

  1. Start -> Run -> Regedt32
  2. Navigate to the following key:
    HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common
  3. Add the following DWORD value:
    "RespectSystemFontSmooth"
  4. Set the value to 1
  5. Close RegEdit


That's it. Naturally, restart Office if it's already running, but you should notice that the Office 2007 suite now respects the system settings for font smoothing.

Friday, August 03, 2007

Programatically Add User to SharePoint 2007

There are a ton of articles out there detailing how to add a user to a SharePoint site; however, it's a struggle to find anything detailing how to perform the operation in a SharePoint 2007 environment.

private static void AddUser()
{
try
{
using (SPSite site = new SPSite("http://test1"))
{
ServerContext context = ServerContext.GetContext(site);
UserProfileManager profileManager = new UserProfileManager(context);

if (!profileManager.UserExists("senfo"))
{
UserProfile profile = profileManager.CreateUserProfile("senfo");

profile[PropertyConstants.WorkEmail].Value = "me@myaddress.com";
profile.Commit();
}
else
{
Console.WriteLine("User already exists...");
}
}
}
catch (UserNotFoundException err)
{
Console.WriteLine(err.ToString());
}
}


It's important to note that if you're using multiple membership providers that this code will throw the following Exception "No mapping between account names and security IDs was done". To correct the issue, add "MembershipProviderName:" in front of the username. For example, "SqlMembershipProvider:senfo".

Tuesday, July 31, 2007

Extension Methods

This is the first in a series of posts that I will use to demonstrate some of the cool new features of the new C# 3.0 specification and Visual Studio 2008.

If you asked me, the two coolest new features of C# 3.0 are LINQ and Extension Methods. There have been a ton of articles demonstrating the power of LINQ, so I'll focus my first post on Extension Methods.

So what exactly is an extension method? In as few words as possible, it's a language feature that allows a developer to add new methods to existing types. And I see quite a bit of potential with this feature. For example, adding a SaveAsJpeg() method to the sealed System.Drawing.Bitmap class.

Just a little background so we can begin. An extension method must be declared in a static class, which makes a lot of sense when you think about it.

For demonstration purposes, let's create a static class called StringExtenstions that adds a Reverse() method to the string type.

public static class StringExtentions
{
public static string Reverse(this string str)
{
StringBuilder sb = new StringBuilder();

// Reverse the string
for (int i = str.Length - 1; i >= 0; i--)
{
sb.Append(str[i]);
}

return sb.ToString();
}
}


And believe it or not, that's it. You have just added a Reverse() method to all string types within your assembly. And how do you use it? Good question. Just like you would had the String class always had a Reverse() method.

string myString = "This is a test";
string reversed = myString.Reverse();


It should be noted that unlike regular methods, extension methods cannot access private members of the class that they are extending.

Stay tuned for more C# 3.0 goodness.

Sunday, June 03, 2007

Don’t buy an HDTV without reading this first

I was recently inquiring about the latest in HDTV technology and I came across a great HDTV survival guide that I thought others might find useful. Definitely worth a read if you're in the market for an HDTV.

Tuesday, April 10, 2007

Asynchronous Pages in ASP.NET

In my opinion, one of the most unappreciated enhancements to ASP.NET 2.0 is the ease in which one can design their code to run asynchronously. In my experience, developers have blown off the idea in the beginning because of not realizing the true potential of asynchronous development in a web application. This MSDN article goes into details about why asynchronous programming is important to your ASP.NET applications, and provides code samples to help you understand.

kick it on DotNetKicks.com

Thursday, March 22, 2007

Infinities Loop : TRULY Understanding ViewState

I recently stumbled across this article on ViewState. I wasn't expecting to learn much, but I was pleasantly surprised. Definitely worth the read if you are an ASP.NET developer.

Thursday, March 08, 2007

Using code Tag to Display Code in Your Blog or Website

If you post code to your blog or website, you might want to consider using the <code> element to help separate your content from the code. This can be achieved nicely by setting the style for the <code> element in your CSS. I use the following style in my blog to help format code snips that I post.

code
{
background-color: #f6ffff;
border: solid 2px #bbbbbb;
display: block;
font: courier;
margin-left: -10px;
overflow: auto;
white-space: pre;
width: 410px;
}


Sample:

<code>
#include &lt;stdio.h&gt;

int main(void)
{
printf("Hello world!\n");
return 0;
}
</code>

Friday, March 02, 2007

Advanced OOP Design Patterns

This is, without a doubt, one of the best online resources I have come across, which clearly demonstrates some fundamental design patterns used in OOP. After reading the excerpts from the book, I'm convinced I'll be purchasing a hard copy as soon as possible. Whether you program in C++, C#, Java, or any other OOP language, these fundamental design patterns should be applied to your programs.

Saturday, February 17, 2007

Another Linux Desktop: XGL

Speaking of Linux desktops, here is another favorable desktop for Linux known as XGL.





Project Looking Glass on Ubuntu

For years, people have regarded Linux as a toy for geeks. Many claimed that the capabilities of desktop Linux lagged far behind the power of the desktops offered by Microsoft in the Windows operating system. Fortunately, those times are changing as innovations to the Linux desktop have placed Linux well ahead of the enhancements brought forth by Microsoft's latest operating system, Windows Vista. One prime example of this is Project Looking Glass, which is brought to you by none other than Sun.

Monday, February 12, 2007

Complex Password More Weak?

Firstly, I'd like to point out that I am a developer, I am not a writer. That said, I apologize ahead of time if this reads like a high school student wrote it. I did my best.

At any rate, in this day in age, and with as much as we rely on the Internet for the important day-to-day aspects of our lives, we can never be too careful with our passwords. But is there a point in which password complexity can actually have an adverse affect on how secure a persons password really is? I say the answer to that question is an irrefutable, "yes".

I want to point out that I am huge on personal security. Actually, I've been told that I'm obsessive, at times. Having said that, I have come up with passwords that I'm thoroughly convinced that it would take more than a trillion monkeys pounding away at a typewriter, over 100 lifetimes to crack. They're secure, but they mean something to me, so they're easy for me to remember. For the times that I need more protection, I resort to encrypting my data with a passphrase, which is even more complex. However, even though I consider the passwords that I use to be reasonably secure, I can't help but wonder what the person/people were thinking when they came up with the list of requirements for a site I was recently signing up for. Following is a list of requirements.

  1. must be at least 7 characters long
  2. cannot contain the login id (exact or partial)
  3. must contain at least one letter, one number, and one of the following special characters:
    $&#_!@%^*()-=+~\:;<,>.?/
  4. cannot contain any repeat characters
  5. cannot contain any of:
    |'`"

Two things from this list stand out. Firstly is that the password cannot contain any part of my login name. At first, I wasn't exactly sure how strict this rule would be enforced, but I later came to find out that any part of my login ID means exactly that. Any part. For example, if my login ID contains the letter 's', my password cannot cannot have the letter 's' anywhere in it. To make matters worse, the password also cannot repeat any characters. Yep, that means that you cannot have the same character in your password more than once.

Amazed by the complexity of the requirements, I was finally able to come up with a password that would comply; however, there was no way that I was ever going to remember it, considering the passwords complexity and that it was for a site that I'll rarely visit. So, if I ever want to be able to get back into my account again, I really didn't have much choice except to either write down the password or save it in an encrypted file.

In my opinion, this is an example of people getting quite ridiculous with their password requirements. As I mentioned before, I am pretty big on personal security, which is why I opted to save my password in an encrypted file. However, for the majority of the people that I know, this password format is so complex that their passwords will end up on a Post It note stuck under their keyboard. So much for security.

It is my hope that developers will read this post and realize that there is a point that going overboard on password complexity can have an adverse affect on what their original intentions were. This, in my opinion, was obviously an example of going extremely overboard.

Friday, January 26, 2007

C# 3.0: An Introduction

This article hopes to bring readers up to speed on some of the changes we can look forward to in the C# 3.0 specification. Some of the new features include:

  • Object Initialization
  • Type Inferences
  • Anonymous Types
  • Lambda Expressions
  • Extension Methods
  • Queries (LINQ)
  • Expression Trees

Thursday, January 25, 2007

SQL Injection Attacks by Example

Are your applications susceptible to SQL injection attacks? I recently stumbled on a decent article that hopes to educate readers by demonstrating sample SQL injection techniques. A recommended read for any SQL developers.

Thursday, January 18, 2007

Search Engine Optimization for Beginners and Experts

Scott Bowler has written a great blog article detailing how to "achieve consistent results in the major search engines." I have found his blog post to be extremely useful and recommend it to others to read.

Wednesday, January 17, 2007

Custom Iterators

Bill Wagner has written a great article on custom iterators that I highly recommend reading. He takes you through a series of problems in great detail to help explain better ways of iterating through collections. A Word document version of the article is also available here and his blog can be found here.