Wednesday, February 26, 2014

ASP.NET: How to detect whether Headers have been sent or not

In using ASP.NET, there isn’t a great way to know whether the Headers have been sent. One way to do this is to handle the PreSendRequestHeaders event then store the resulting value in context for the request like the HttpContext.Items collection. An example of this implementation is below.

You then simply call the static method Global.HeadersSent like the below.

Wednesday, April 17, 2013

Unit Testing?! a Pragmatic Introduction

I was excited to present a quick overview of software unit testing to my peers today. It was quite the oversimplification of the topic, but good none-the-less.




Much thanks to Prezi for making the presentation look fantastic. Check it out on Prezi. I highly recommend them for presentation. Kick the PowerPoint to the curb.

Additional resources:

Thursday, July 19, 2012

Windows Azure Web Sites: Setting up a .NET MVC 4 Site using Visual Studio 2012 RC

A quick post of my experiences setting up a new .NET MVC 4 web site using the latest and greatest on Windows Azure.

Mostly it was straight forward, but I did run into some gotchas. They are documented below.

Steps

Gotchas

No Custom Domains

A Shared Web Site cannot currently have a custom domain name pointed to it. This is a huge limitation and disappointment.

The only way to do it is convert the site to a Reserved instance and the cheapest estimate for pricing is $50+/mon. This is astronomical compared to what you can do at other hosting solutions.

Some search revealed there might be an enhancement to Azure in the future to allow custom domain names for Shared sites. I’ve been unable to find a timeline or cost.

.NET Framework 4.5 RC Not Supported

Apparently, .NET Framework 4.5 RC is not supported by Azure. I ran into this issue because I’m running Visual Studio 2012 RC and setup the MVC 4 web project which defaults to .NET Framework 4.5. This caused errors when trying to publish the site to Azure.

To fix, I simply edited the project properties and targeted the .NET Framework 4.0. This resolved the issue.

No classes deriving from DbContext found in the current project.

I ran into a weird error when trying to run the “enable-migrations” in the Package Manager Console (see Add a Database section.) Even though my classes existed within the project the console kept returning “No classes deriving from DbContext found in the current project.”

After a little googling, I found out the MVC 4 site I had created had set itself up with .NET Framework 4.5 and defaulted the EntityFramework package to 5.0.0-rc version, which is a mismatch with the “enable-migrations” command.

To fix, I ran “Uninstall-Package EntityFramework”, then ran “Install-Package EntityFramework” and since the 5.0.0-rc is pre-release, NuGet automatically installed the released 4.3.1 version. After this was done, the “enable-migrations” command ran successfully.

Monday, June 27, 2011

Automating NuGet Packing and Publishing with MSBuild

We’ve setup a NuGet Gallery and now we wanted to have our builds automatically package and publish to the NuGet Gallery.

The below is more or less the step-by-step process to get it up and running in an automated way.

Step 1 Create your NuSpec for your .csproj. The documentation on NuGet documents is pretty good for this step.

The gist is you will need to have the .nuspec file in the same directory as the .csproj file. You will have to modify this file and ensure you’ve populated all the correct tags as mentioned in the NuGet documents.

Note: An error message will appear when trying to package if something is missing.

Step 2 Modify your .csproj file and add the below snippets. They are generically written so they should fit right into your msbuild file fine. Obviously, edit when appropriate should your msbuild file already be customized.

Edit: Make sure you update the My_Nuget_Gallery_Service_Url token in the script to point to your gallery.

Note: You will need to run nuget setApiKey before this will work as it relies on the API Key for the NuGet Gallery already to be stored locally. This is handy as you can login as your Build Service Identity and run the command. It will then publish as that user from then on out.

Step 3 Run it via MSBUILD.

All you need to do on your build sever is execute the below command:

Edit: Make sure you update the tokens to be the correct values for your project.

Friday, June 10, 2011

Getting Started with Visual Studio 2010 and Web Deployment Tool

I wanted to jot a couple notes about the process which took me a few minutes to figure out.

Step 1 is setup and configure Package/Publish Settings.

  1. Open Visual Studio 2010
  2. Open your Web Project
  3. Open Solution Explorer
  4. Right-Click on your Web Project
  5. Click on Package/Publish Settings

At this point, you should see the below.

2011-06-10_1644

You need to make sure you set the “IIS Web site/application name to use on the destination server” to the «Web Site»/«Virtual Directory» path. If you are updating a Web Site just leave it to be the web site name in IIS.

This is very important. If this doesn’t match the target, then your deployment will fail unless you customize the deployment further.

You’ll want to repeat this process for all your difference Configurations. By default, Visual Studio gives you Debug and Release. Most people, will add one per environment to the list (i.e. Development, Integration, QA, Staging, Production, etc.)

Step 2 add a Parameters.xml file to the root of your Web Project in Visual Studio 2010. This allows you to setup parameters, which the deployment process will use when it’s processing your deployment. An example of what I used is below.

Parameters.xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <parameters>
  3.   <parameter name="Application Path"
  4.              description="Full site path where application will be created."
  5.              defaultValue="$(DeployIisAppPath)"
  6.              tags="IisApp">
  7.     <parameterEntry kind="ProviderPath"
  8.                     scope="iisApp"
  9.                     match="$(DeployIisAppPath)"/>
  10.   </parameter>
  11.   <parameter name="Application Physical Path"
  12.              description="Physical path where files for this Web application will be deployed."
  13.              defaultValue="c:\inetpub\wwwroot\$(DeployIisAppPath)"
  14.              tags="PhysicalPath">
  15.       <parameterEntrykind="DestinationVirtualDirectory"
  16.                      scope="$(DeployIisAppPath)"
  17.                      match="" />
  18.   </parameter>
  19. </parameters>

You’ll note I used $(DeployIisAppPath) several times within the file. This refers back to the “IIS Web site/application name to use on the destination server” setting in your Package/Publish Settings in your Web Project.

Note: At the point of this writing, I haven’t experimented much with these settings, so feel free to tweak away.

Step 3 create your package. The simple way is to right-click your Web Project in Visual Studio and click Build Deployment Package.

This will create the package in the folder you set in the Package/Publish Settings for your Web Project.

OR

You can use MSBuild from the command line. This comes in handy when you want to setup a build server to execute the Build and Package processes. The command line parameter looks like the below.

"c:\Windows\Microsoft.NET\Framework64\v4.0.30319
\msbuild" .\MyWeb\MyWeb.csproj /t:Build,Package /p:Configuration=Release;DesktopBuildPackageLocation=C:\output\MyWeb-Release.zip

It’s import to note a couple things about the above command line.

  • I’m running on 64-bit Windows, so my Framework folder is Framework64. You might need to change this if you’re running 32-bit Windows.
  • I’m telling msbuild to run Build and then Package with the /t argument. Case sensitive.
  • I’m telling msbuild which configuration to run with /p argument.
  • I’m telling msbuild where to put the package by specifying the DesktopBuildPackageLocation with the /p argument.

Feel free to tweak this away it was hand to get something going on my side and may or may not be helpful to you.

After you run either of the above, you should have a package zip file and several other files in the directory.

Note: If you copy the package zip around you must include the other files with it to get the deploy to work correctly, so don’t forget them.

Step 4 is go to your IIS target server and setup the Web Site or Virtual Directory. Ensure you setup the name of the Web Site or Virtual Directory to match the one you populated in the Package/Publish Settings in your Web Project.

You will need to ensure you .NET Framework version is configured on your Application Pool to match your web sites target framework.

Note: The web deployment does not initially create the Web Site for you on the destination server. This must be done by other means.

Step 5 ensure the destination server has the Web Deployment Tool installed and configured properly.

By default, the Web Deployment Remote service is Disabled and stopped on the server. You must enabled it and start it.

Step 6 follow these instructions on how to install a package using the included CMD file.

Voila! You have from start to finish setup and running with Visual Studio 2010 and Web Deployment Tool process.

Monday, March 7, 2011

about.me/richardadleta

TedC sent me over to about.me. I opened my own page. It’s fancy with the UI widgets. If you add several services it’ll let you link to other social content generators (e.g. twitter, blogspot, linkedin, etc.) No much else there, yet.

It' seems like the biggest use is putting your name on a page then getting the best picture of yourself and making it the background.

One more web site with my profile information. Sigh.

Now to find a pretty background… :)

Saturday, March 5, 2011

Finding a Blog Editor

I'm trying to find a good blog editor. I started by trolling google for a blog editor and ran across several. Usage is premium. It has to be simple, easy and quick.

I just downloaded the Chrome Plug-in called ScribeFire. (It's what I'm using to write this post.) I noticed it supports other browsers. So far, it's not bad, but then as I’m linking to the download page… BAM! It doesn’t let me highlight text and link it. I have to insert link, fill out form and submit. Boo! Uninstall.

While I was wasting my time with ScribeFire, I had the Windows Live Writer downloading in the background. I installed it and I have to say I’m actually impressed. It’s nice. It does what I want and the interface is pretty. I’ll stick with this one for a bit and see how it goes.

UPDATE: I found some nice Plugins for Windows Live Writer.

Tips on Writing Faster

Helpful post on how to write faster. Worth reading considering how much writing we have to do on any given day.

Thursday, December 16, 2010

Legacy DOS Script: Loop Over Directories

Simple little script to loop over all sub-directories:
FOR /D %%f IN (".\*") DO ECHO %%f
There was an error in this gadget