Integrate Disqus into your site using JavaScript

by cliff 15. October 2008

Recently I added Disqus, a hosted comment system, to a site and wanted to point out a couple of things that were not too clear from the documentation on the Disqus site.  It may have been updated, but as of this post, I was not able to find too much info on the JavaScript implementaion of Disqus. 

Basically the JavaScript implementation will work with any web site technology, for example php, ASP.NET, etc.  In order to get it to work, you first need to sign up for an account.  Once you do this, they will provide you with the "code" that you need to add to your site.  Once you add this code, all of the necessary HTML and comment data will appear on your page. 

When you create an account, you provide your site URL. It is important to understand that if you are developing or testing your site on a server other than the one registered with your domain name, the Disqus comment section will not appear.  So if you are setting things up on your local machine and testing, you will not see the full comment section.  Once you push your code to production, you will then see the full Disqus comment section

That is it...it is very easy to set up and use...

Create a comma seperated list from a column in a SQL Server table

by cliff 28. September 2008

Problem: you want to create a comma seperated list of values from a column in a database table.  You constraints are that you want to create the comma seperated list at the database level and you can not use a cursor or while loop.

For example, if you have a table called "Category" with a column "Name" that contains the values:

 Name
Breakfast
Lunch
Dinner

and you want to return Breakfast, Lunch, Dinner.

There are many ways to do this and most tend to involve looping or a pivot.  One efficient and elegant solution is to use a simple select statement:

declare @commaSeperatedNames varchar(max)
set @commaSeperatedNames = '';

select @commaSeperatedNames = @commaSeperatedNames + case
        
when len(@commaSeperatedNames) > 1 then ', '
        
else '' end
        
+ name from category;

select @commaSeperatedNames;

The key is to initialize the string var to an empty string so the concatenation works as expected. .

Server.Map path returns error System.InvalidOperationException: Failed to map the path in Cassini

by Cliff 31. August 2008

I encountered an issue today while trying to use the Server.MapPath method in an asp.net web page.  When trying to use Server.MapPath with a virtual directory in IIS (outside the web site) I was receiving an System.InvalidOperationException: Failed to map the path error.  Turns out, since I was running the web site as a file system project, and using cassini, this error was being generated.  By moving the project to IIS and running the site under IIS and not cassini, the error went away.

Using Dependency Injection with an ObjectDataSource

by Cliff 29. June 2008

In this post I will outline how to use dependency injection with an ObjectDataSource.  There are many benefits to using dependency injection and programming to interfaces including maintainability, extensibility, and testability.  For the example that follows the use case is to provide a pagable, sortable list of data, using a gridview, and performing the paging and sorting within the database for performance reasons.  Based on these requirements, an object data source is needed as it provides the mechanism to support custom paging and sorting for a grid view.

Dependency Injection For this example I have choosen StructureMap.  One of the nice features of StructureMap is that is allows you to map your Interfaces to concrete types using code.  The below code creates a Registry and leverages some new features in StrucutreMap version 2.5

public class ServiceRegistry : Registry
{
  protected override void configure()
 {
    ForRequestedType<IPersonService>().TheDefaultIsConcreteType<PersonRepository>();
  }
}

This code instructs StructureMap to return PersonRepository when someone requests an IPersonService. There is a lot more you can do with StructureMap, for a complete overview of StructureMap, please check out their homepage.

Next, it is time to set up the ObjectDataSource.  An ObjectDataSource does not let you specify an Interface directly, so you need to override the default behavior.  First, define the types:

<asp:ObjectDataSource ID="ObjectDataSourcePerson" runat="server" SelectMethod="GetRecordList"        DataObjectTypeName="Services" TypeName=Services.IPersonService"        OnObjectCreating="ObjectDataSourcePerson_ObjectCreating" >   
</asp:ObjectDataSource> 

The important things to note are the types (DataObjectTypeName is Namespace.Class, TypeName is Namespace.Class.Type) and the OnObjectCreating, this is where we will override the default behavior.  The code behind for this looks like: 

protected void ObjectDataSourcePerson_ObjectCreating(object sender, ObjectDataSourceEventArgs e)    {        
 
IPersonService personService =
StructureMap.ObjectFactory.GetInstance<IPersonService>();        
 
e.ObjectInstance = personService;
 
}

Now, when the ObjectDataSource is created, the concrete type will be used.  The power here is that we did not have to specify the concrete type in the code or DataSource definition, so in the future we can change the implementation and not need to change the UI code.

From here, you can implement the paging and sorting in the custom type and wire it up to the ODS and GridView.

 

Software Development Podcasts

by Cliff 22. May 2008

Below is a list of software development podcasts, IT Podcasts, and general computer related podcasts. Please add commnets on podcasts you enjoy...

.NET Rocks - This is a really good (quality and content) podcast that focuses on .NET development.  While the main focus is .NET there is a fair amount of content that applies to general computing and development such as design patterns, agilie practices, and more.

Software Engineerig Radio - This podcast provides an excellent variaty of topics that span technologies, languages, platforms, methodologies, etc. The shows can be rather technical and geared more toward knowledgable developers, but still offer a wealth of knowledge for beginners through experts.

Hansel Minutes - This is a weekly podcast that is primarily focused on Microsoft technologies but also includes other technologies and topics from time to time (for example digital photography).  While Scott is a Microsoft employee, the cast is rather open to non MS technologies and techniques such as TDD, ALT.NET, etc.

The Java Posse - This is an excellent podcast focused on the Java language, platform, and related technologies.  It provides both technical information as well as news and events within the Java community.

Buzz Out Loud - This is a daily podcast that is a summary of news and events relating to technology.  The personalities of the hosts really help to seperate this podcast from the usually news recap type shows...certainly worth checking out...

Polymorphic Podcast - A good podcast focusing on development and .NET.  The podcasts sometimes include screencasts and overall provides a lot of good content.

SSWUG - A database centric podcast dealing mainly with SQL Server but does include topics on other RBDMS as general database best practices.

Slashdot Review -  While at times biased, this can be a quick and informative cast.

Google Developer Podcast - Hopefully this will be a good resource to learn more about the technolgy offerings available through google.

Windows Weekly Podcast - Interesting take on the windows world.

ALT.NET Podcasts - A really good podcast that covers topics that all developrs should familiarize themselves with.

Deep Fried Bytes Podcast - Good podcast focusing on mainly Microsoft development

Thirsty Developer - Another good developer podcast focusing mainly on .NET

herdingcode.com - Good podcast relating to development

WebDevRadio - Covers web development

eCorner - Stanford entreprenure podcast 

Stackoverflow - development podcast 

ThoughtWorks - Business and technology topics

Agile Toolkit - topics relating to Agile development 

Udi Dahan - SOA podcast 

Endpoint.tv - New show hosted by Ron Jacobs on REST, SOA, web services, etc. 

http://pixel8.infragistics.com/default.aspx - UI, UX, RIA info

Finacial Physician

 

 

Windows Server 2008 - Activation fails DNS name does not exist

by Cliff 18. May 2008
I ran into an issue when trying to activate an Enterprise edition of Windows Server 2008.  I had installed the software from my MSDN account and when I tried to activate the software, I received a "DNS name does not exist" error.  To fix this problem, I had to re-enter the product key for the software.  After entering the product key (I just entered the key that was already entered from the install) I was then able to activate the software.

TableDiff tool for SQL Server

by Cliff 30. March 2008

One of the nice tools that is provided with SQL Server 2005 is the TableDiff.exe table comparison tool.  It allows you to compare the data in the same table on different servers or instances.  Below is an expample that compares the data in "table1" and places the results in the table "Table1DifferencesServer1Server2".  This command needs to be run from the command line, in the directory where tablediff.exe is located.

C:\Program Files\Microsoft SQL Server\90\COM> tablediff -sourceserver "server1" -sourcedatabase "database1" -sourcetable "table1" -destinationserver "server2" -destinationdatabase "database1" -destinationtable "table1" -et Table1DifferencesServer1Server2

 More info can be found on BOL http://msdn2.microsoft.com/en-us/library/ms162843.aspx

Visual Studio 2008 no syntax highlighting for XML and config files

by Cliff 9. March 2008

I had been running a beta of Visual Studio 2008 and when I uninstalled the beta and installed the RTM version, I found that I had no syntax highlighting or intellisense when editing config files (web.config, app.config, etc.)  When I tried to change the properties in the IDE, I received An error occurred loading this property page from the tools -> options menu.

 To fix the issue I ran the below command from the Visual Studio 2008 command prompt:

 devenv /setup

 

ASP.Net Membership Password Administration

by Cliff 22. February 2008

If you need to update user's passwords that are stored in the aspnet_Membership, the below code should help you accomplish this.

If you are using the default SqlMemberShip provider for authentication, you may have a need to manually reset a user's password.  In order to accomplish this, you can hash the password with a salt and then store the password and salt in the aspnet_Membership table.

string salt = GenerateSalt();
string password = EncodePassword("mypassword", 1, salt);

public string EncodePassword(string pass, int passwordFormat, string salt)

{

if (passwordFormat == 0) // MembershipPasswordFormat.Clear

return pass;

byte[] bIn = Encoding.Unicode.GetBytes(pass);

byte[] bSalt = Convert.FromBase64String(salt);

byte[] bAll = new byte[bSalt.Length + bIn.Length];

byte[] bRet = null;

System.Buffer.BlockCopy(bSalt, 0, bAll, 0, bSalt.Length);System.

Buffer.BlockCopy(bIn, 0, bAll, bSalt.Length, bIn.Length);

if (passwordFormat == 1)

{ // MembershipPasswordFormat.Hashed

HashAlgorithm s = HashAlgorithm.Create(Membership.HashAlgorithmType);

bRet = s.ComputeHash(bAll);

}

else

{

//bRet = EncryptPassword(bAll);

}

return Convert.ToBase64String(bRet);

}

private string GenerateSalt()

{

byte[] buf = new byte[SALT_SIZE_IN_BYTES];

(new RNGCryptoServiceProvider()).GetBytes(buf);

return Convert.ToBase64String(buf);

}

 

Once you have the salt and password, you can store them in the database. 

 

UPDATE [aspnet_Membership] SET Password = [use the password hash from above],

PasswordSalt = [use salt from above] WHERE [UserId] = CAST('123456789...' as uniqueidentifier)

 

Finally you can now authenticate the user with a password of "mypassword".

 

Error trying to install or run vsi file

by Cliff 1. February 2008

If you are trying to run a .vsi file and have both VS 2005 and VS 2008 you may encounter an error that indicated the file microsoft.wizardframework could not be loaded:

could not load file or assembly 'microsoft.wizardframework

Below are the steps I followed to correct:

  1. Check the GAC (C:\WINDOWS\assembly) for the assembly Microsoft.WizardFramework.dll
  2. If it does not exist, check that it exists in C:\Program Files\Micro
    soft Visual Studio 9.0\Common7\IDE\
  3. If it does, then open a VS command prompt and add the dll to the GAC
    gacutil /i "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Microsoft.WizardFramework.dll"
  4. Check for the dll in C:\WINDOWS\assembly
  5. You should now be able to run the VSI

About the author

Cliff Gray
Developer/Founder GrayTechnology.com.

E-mail me Send mail

Download BlogEngine.NET

Download at CodePlex

Calendar

<<  November 2008  >>
MoTuWeThFrSaSu
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

View posts in large calendar

Authors

Blogroll

Disclaimer

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

© Copyright 2008

Subscribe