ASP.NET

Gmail Bug? Or Chrome? Either way – Google.

August 16th, 2010  |  Published in ASP.NET

The WIERDEST things are happening to me today.  I had a meeting with the web security guy and nobody ended up yelling.  I made a phone call to my wife with a reported 0 bar reception on my phone and now I find some strange happenings in my Gmail.  I opened a chat window and highlighted the text area and continued to highlight moving down and I got this strange whitespace to open up underneath the mail area.  Yes, I blurred out my email.  I wouldn’t trust you people with a rusty nickel.

GmailBug

Jailbreak Your iPhone From Safari Right Now

August 4th, 2010  |  Published in ASP.NET

How about instead of shelling out an additional $200 for iPhone 4 and thusly forfeiting your unlimited data by re-upping your contract with AT&T, you simply Jailbreak your 3G or 3GS and enjoy a brand new iPhone experience!

It’s fun and easy kids.  Here’s how:

On your phone, open Safari and browse to http://www.jailbreakme.com.  Once you get there, slide the slider over to “Jailbreak” and in about 3 minutes, your phone will be free.  I mean really free.  Free to do multitasking with ProSwitcher and Backgrounder.  Free to shoot hi-res native video.  Free to play flash video.  Free to be all that it can be – and so much more.

I know Jailbreaking sounds sketchy, but look, the library of congress has already ruled that it is perfectly legal.  On top of that, I can tell you from experience that having the basic set of jailbreak tools (like multitasking and video) will genuinely reinvent your iPhone experience.

An Open Letter To Steve Jobs

July 6th, 2010  |  Published in ASP.NET

From: Me
To: Steve Jobs

Dear Mr. Jobs

Your iOS 4 bricked my 3G. Thanks for that.

Sincerely,

Me

Linq To SQL Procedures Return An Int

April 15th, 2010  |  Published in ASP.NET

I was working with a procedure the other day and I saw something that I see from time to time.  A stored procedure that returns a results set gets mapped to an Int in the DBML declaration of your Linq To Sql mapping.

Why does this happen?

This can happen for 2 reasons.

1.  You are using temp tables in your stored procedure

2.  The user account you are using in your DBML is NOT the dbo for the database.

There are several articles out there that will mention one or the other, but both conditions have to be satisfied before the DBML will spit out a results set as your return type.

The fix for #2 is obvious – grant your user the correct permission and make sure the schema mapping is correct.

The fix for #1 is ugly, but efficient.

Comment out your entire proc after the BEGIN and put in a select that returns the data types that your proc will be returning.  Compile.   Return to Visual Studio and drop the proc from your DBML.  Refresh your data source in the sidebar and drag the proc back out.  It should now map to an ISingleResultType.  Go back to your procedure and remove the single select.  Uncomment out the proc and recompile.  It will now return a set of data to your application as you desired.

I love Linq To SQL and I hope MSFT put some more work into it for 2010.

Relative Paths In ASP.NET MVC

March 16th, 2010  |  Published in ASP.NET

If you have been working with MVC for any amount of time, you have most likely been already confounded by the inability to quickly get the root URL of your application for referencing either javascript files, or ajax method url’s. 

There are many documented workarounds for this, and I am going to cover 2.  The first one you are probably familiar with, but the second is a little trick I stumbled on and perfected a bit myself.  It will help keep your javascript references clean and can be used anywhere in your project.

Lets start with the fundamental problem of referencing a javascript file in your Master Page, or any other page for that matter.

When working in Visual Studio, you know what your path is, and you can alter it as needed to get to the root.  I.E. ../../Content/

This presents the problem that the final resting place for your app is hopefully not going to be on your localhost and you need your project to be able to reference the application root no matter how far down a directory structure you put it.

We can solve this problem by using the Url.Content method to reference javascript.  A reference in the Master Page header than looks like this.

Code Snippet
  1. <script src="<%= Url.Content("~/Content/jQuery/jquery-1.4.1.min.js")%>" type="text/javascript"></script>

That works just fine for including files, but if you have a page where the javascript is getting very lengthy, and you want to break it out, you have this problem again referencing the relative path url from the .js file.  The reason for this is that the .js file is not parsed by the ASP.NET engine, so those server tags never get translated.

While looking for a solution to this problem, I stumbled upon a post on Stack Overflow where someone was trying to do something similar and someone responded with a method of setting a javascript function in the code behind to return your absolute url value. I could see this guy was on to something, but it was a little verbose.

Here is what I came up with to accomplish essentially the same thing.  This would go in the header of your page after your jQuery include (and btw – if you aren’t using jQuery, then disregard this post and go improve your life SIGNIFICANTLY by finding out what it is.)

Code Snippet
  1. // create a function for getting the root path
  2.         $(function() {
  3.             $.url = function(url) {
  4.                 {
  5.                     var path = '<%= Request.ApplicationPath %>'
  6.  
  7.                     if (path != '/')
  8.                         path = path + '/'
  9.                     
  10.                     return path + url;
  11.                 }
  12.             }
  13.         });

You can now reference your root path by using the $.url() function anywhere in your project (provided you did this in the Master Page).  For example, and ajax call becomes…

Code Snippet
  1. $.getJSON($.url('Home/GetInfo'), { employeeNumber: employeeNumber },
  2.                 function(data) {
  3.                     if (!data)
  4.                         alert("Unable to retrieve info");
  5.                 });

Now you have an easy way to always know your root path.  I give credit on this to the author of the Stack Overflow article. It is a crafty way to solve a project wide problem with very few lines of code.  It also makes your javascript cleaner and prettier.  What we might call a “Graceful” solution.

My Thoughts On Winter

February 15th, 2010  |  Published in ASP.NET

This may be inappropriate, but I really feel like it needs to be said…

winter8bn

Got A Slow Mac?

January 10th, 2010  |  Published in ASP.NET

Mac people sometimes begin to believe that they are immune to normal PC problems. For the most part, this is very true. However, mac users will of course still experience the occasional setback from time to time. One that seems common to me is the old “My computer is slow” issue. If you have a PC, this is a much more convoluted issue as it could be any number of things from a virus, to a rogue program to a fragged disc. If you have a mac, the solution is likely much more simple.

Two things usually contribute to the slowness you experience on your mac. I’m not talking about slowness that comes from installing Leopard on an emac, or the slowness that comes from running pro tools on an ibook. I mean slowness where your mac is clearly slower than it was when you first had it.

1. Disc permissions
2. A Cluttered Desktop

Often times when your mac slows down, its because the permissions on your disc need to be repaired. This is really easy to do. Go to your disc utility in the Utilities folder in your Applications folder. Select your hard drive (Usually called Macintosh HD) and select “Verify Disc Permissions”. When this action has completed, select “Repair Disc Permissions”.

For some reason that I will never know, if you clutter the desktop of a mac – especially if its a G series mac running Tiger, the whole computer will slow down. Clear off your desktop. Put everything in folders somewhere in your home folder. You computer will look much better anyway after you do this.

After you have done these two things, you are going to do something that PC users do several times a week. Reboot. Don’t panic, it’s not going to become a habit.

Your mac should now be back to its normal speedy state.

BTW – I know I “sound” like an Apple Fanboi, but I’m not. I’m actually a PC. It’s a religious debate. I won’t start on it. Just know that I see the advantages in both systems and I choose PC.

Load Balancing ASP.NET Sites On Windows Server 2008

November 20th, 2009  |  Published in ASP.NET

I have been through this iteration twice now, so I wanted to share what I have found works for me in simple terms to get an ASP.NET site up and running on a set of load balance web servers.

I am not going to discuss the infrastructure site of this setup.  That would include setting up your servers with a heartbeat and configuring your ASP.NET sites.  The reason for this is that NLB strategies really vary from place to place depending on what hardware and network technology you are using.  Setting up IIS sites is frankly very straight-foward, and there is nothing you will do out of the ordinary here.

Lets focus on what we need to do to the application first to get it ready.

If your application uses any sort of Session State objects at all, it is wise to put your session information in SQL Server.  The reason behind this is that it really provides the best and most reliable source for keeping session information integrity between your two servers.  Besides that, since you are load balancing your application, you need a source for the session state that is available to ALL servers in the farm.

Start out by creating your ASPState database on your database server.  There is already a great article you can follow on how to do this here.

Its a rather long article, so let me outline the important stuff…

  1. Run the Aspnet_regsql.exe tool which is located in the systemroot\Microsoft.NET\Framework\versionNumber directory
  2. Go through the wizard to create the session database

Now that the ASPState database is created, we setup our ASP.NET application to use it.  In your web.config file, you will provide an entry that looks somewhat like the following…

<sessionState
mode=”SQLServer”
sqlConnectionString=”data source=SQL2005COR01;user id=ASPState;password=aspstate”
cookieless=”false”
regenerateExpiredSessionId=”true”
timeout=”30″
/>

<sessionState

mode=”SQLServer”

sqlConnectionString=”data source=yourDatabase;user id=dbuser;password=pwd”

cookieless=”false”

regenerateExpiredSessionId=”true”

timeout=”30″

/>

The documentation for what all these options do is located here..

http://msdn.microsoft.com/en-us/library/h6bb9cz9(VS.71).aspx

The sessionState block needs to go inside of the system.web section.

Now the next thing we need to do is to handle our View State between all the servers in our farm.  The ViewState is tied to the machine on which it is generated.  This information can be shared across servers, but it needs to be encrypted and decrypted.  Fortunately, this is very easy.

Go to the following site, make no changes to the default settings and let it generate the web config setting that you need for you.

http://aspnetresources.com/tools/keycreator.aspx

Now put this tag in the web config immediately following your sessionState information.

You are now ready to publish your application to each of the load balanced servers.

Could Not Load All ISAPI Filter For Site

November 20th, 2009  |  Published in ASP.NET

In IIS 7, should you get this message, you are quite possibly dealing with an error in your web.config file(s).  One way to know for sure is to set up your application under the Default Web Site (if you can) and try and view it from there.  It will give you a more specific error if its under a site that can in fact be started.  Its probably a syntax error like a missing tag or something of that nature.

There are other reasons for receiving this error as well.  Here are some additional links regarding this error…

http://forums.iis.net/t/1149051.aspx

http://www.eggheadcafe.com/software/aspnet/31530837/iis7-support-for-isapi-fi.aspx

Compelling WPF Resources

October 13th, 2009  |  Published in ASP.NET

Articles

Josh Smith On WPF And MVVM

http://msdn.microsoft.com/en-us/magazine/dd419663.aspx

Josh Smith On Events And Commanding

http://joshsmithonwpf.wordpress.com/2008/03/18/understanding-routed-commands/

Shawn Wildermuth On Silverlight And MVVM

http://msdn.microsoft.com/en-us/magazine/dd458800.aspx

Tools

Kaxaml

http://www.kaxaml.com

XamlPad (Installed with Visual Studio)

C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin

Other Resources

A special thanks to Matt Slay for providing me with these additional links…

Linq To SQL changes in 4.0

http://damieng.com/blog/2009/06/01/linq-to-sql-changes-in-net-40

And for those of you out there lucky enough to still be working with FoxPro, here is a linq provider for dbf’s.

http://linqtovfp.codeplex.com/