WebClient not returning a valid response

by joey.westcott 12. September 2009 19:44


A while back I was trying to consume some XML from a third party site and I found myself getting stuck on an error.  The site would not give me a valid response and would throw up a 403 error.  After digging around I found that I left off the user-agent info in the request header.  So the moral to this story is: Don't forget your user-agent!

Code Sample after the break.
More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Development | .Net

I don't want no stinkin <span>

by joey.westcott 26. March 2009 15:34

Goal:
The label control adds <span> tags around the text when rendered, I needed to have these removed. I also show how to replace the <span> tag with whatever tag you would like.

I currently work on a site that has a custom built CMS, which is not always a good thing.  Now don't get me wrong there are some great ideas in this home grown CMS, but just like any application there are some wrong/bad things as well.  Here is one of those bad things that I had the time to fix recently. 

The web site content is entered via a WYSIWYG editor by whoever is responsible for the content, this markup (from the WYSIWYG) is stored in the database along with flags/keys that determine when to display this content.  If a few content items score the same then they all get built together, each one in its own Label control.  This is all fine and dandy, but when it comes time to dynamically create this content and add it to the current page is when they go less than ok.  Because of some limitations of the rest of the framework the content has to be built inside a System.Web.UI.WebControls.WebControl, ok this is fine except we are limited to a select few controls that fall into that category.

More...

Currently rated 3.3 by 3 people

  • Currently 3.333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Development | .Net | Work

Category List bug in BlogEngine.Net 1.4.5.0

by joey.westcott 21. September 2008 11:17

I recently changed the layout of some of my categories in BlogEngine.Net 1.4.5.0.  In short I wanted to add a few parent Categories for the categories that I was already using.  For example: I have a category name ".net" that I lump all of my .net related items in but what if I also have some java code or C++ code and I have a category for them as well?  To me it makes sense to have a parent category called "development" and then if I want to view all code or development related items including C#, VB, Java, HTML, C/C++ then all I have to do is click on the new parent category and voila you have everything development related no matter what the sub-category is.

So for the bug:
When the Category List control/widget is rendered it looks at the Category.FullTitle to build the URI. This works fine if you are not a sub-category, like ".net" using the example above, but when rendering the URI for these sub-categories its using the FullTitle which is a concatenation of the parents categories and the title of the sub-category: ie: "development - .net".  This does not work and that link should really just be to the ".net" category. So here is the simple code fix that I used, but take in mind that you could also make it so that "development - .net" works.  I just found a quick and easy fix...

Code fix after the break.
More...

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , ,

Development | .Net

TF14082: Can not lock item message during a branch/merge

by joey.westcott 6. September 2008 19:45

This morning I was creating a branch in Team Foundation Server via VSTS, the branch name that I wanted to use was one that has been used before and is in fact still sitting around but is now old and out of date. So it being so out of date I just decided to delete the branch and then recreate if from the main branch of code.  After deleting the branch, I went to create the new branch and I get the message "TS14082: Can not lock item $/projectName/../filename.ext for merging. This item is checkout to another workspace".

tfs.cannot.lock.item 

At this point I have already deleted and committed the changed to the branch of code that I'm trying to recreate.  So being able to see what or even find who has files checked out was not an option, I was for the most part out of luck, well at least using the default tools that come in VSTS.  So I fired up the trusty Team Foundation SideKicks application and opened the Status Sidekick. This application allows you to search and view who has files checked out and what each of those files are (great tool, go get it). This tool allows you to filter based on username or even project name and then shows a nice tree view of all the files that are checked out and who has them checked out.

team.foundation.sidekick.status.screen

After gathering the details above I contacted each of the offending people who had items checked out in the old, now deleted branch, and asked them to "undo changes" to each of the files that were locked.  After all the files are no longer checked out or locked in any way, it allowed me to go ahead and recreate the branch using the same name.

What if you cant get a hold of those people or they cant undo the changes?
Lucky for you that the Team Foundation Sidekicks - Status Sidekick also supports undoing others pending changes. It accomplishes this by using the following command from the commandline:

tf undo $/path/to/file.txt /workspace:<WSname>;<domain\user>

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Development | Work

ImageButton's ImageUrl not resolving correctly

by joey.westcott 16. August 2008 18:29

I was working with an image button the other day and for the life of me I couldn't get rid of a runtime error when it went to load the control.  I had a dynamic URL that was something similar to this:

   1:  ImageUrl='../ImageHandler.ashx?File=<%#Eval("Path") %>&MaxSize=<%=PhotoMaxSize %>&ApplyWaterMark=<%=ApplyWatermark %>'

 

The problem with this is that when the .Net Framework goes to parse this property it first see the "../*" and then goes down a routine to parse the path out, BUT forgets about the fact that I might have something in the URL that needs to be resolved.  It did take me quite a while to figure out what was going on and why the "resolved " path was the same as what was between the quotes. 

My solution was to change it up just a little bit, here is what I ended up with:

   1:  ImageUrl='<%# string.Format("../ImageHandler.ashx?File={0}&MaxSize={1}&ApplyWaterMark={2}", Eval("Path"), PhotoMaxSize, ApplyWatermark) %>' 

The result is the same but I just used a little help from the oh so nice string.Format method. Now because the URL didn't start with "../" or even "~/" it looked and noticed that it needed to resolve what is in the <%#...%>.  On a side note this also applies to the other properties on the control and i would assume that other controls are handled the same way.

 

I don't know maybe I should have known this before now.

Currently rated 5.0 by 3 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Development | .Net

Could not load file or assembly 'App_Web...'

by joey.westcott 10. August 2008 16:37

Could not load file or assembly 'App_Web_9olwzuwu, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
 

Error:
Every now and then an ASP.Net 2.0 production app is coming up with the error “Could not load file or assembly 'App_Web...".   The app works fine up until that point and then it breaks and the only solution seems to be a full recompile.   It somehow seems like it is occurring when the application has recycled and .Net Framework recompiles the site to its temp files. 

More...

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | .Net | Work

IIS Error: The service could not bind instance 1

by joey.westcott 15. March 2008 04:22

I got this error the other day and was stumped on what caused it.  It all started when the place i work decided to install webfiltering, most of the time this would not bother me and i would just go about my normal business. Not this time, so myself and another coworker thought that we would just bypassed the filter using an ssh tunnel to our boxes at home and with the use of a proxy run all web traffic over the ssh.  By the way this works great.  My solution after the break.

More...

Currently rated 4.5 by 2 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development

Monitor Your Websites With Sound

by joey.westcott 24. February 2008 13:20
This weekend I had some fun messing around with the idea of monitoring one of my sites via sounds. All of the sites I run are .Net 2.0 or .Net 3.5, with that it allowed me to create a .Net solution that would work with any of my sites.

The idea started with a single thought of "boy it would be kinda neat to hear a sound when someone viewed a page in my site." So I spent all of 30 mins figuring out what i wanted to do create. I built a simple library for playing sounds based on a file or a path to a file. I then took the new lib and built a simple HttpModule for attaching to a site and tapping into begin request event.

This could be used for monitoring a few different sites along with a few different request types, not to mention that you could also include a different sound for events like, app start, begin request, end request, a request for .* file types (ie: if you wanted to know when someone downloaded one of your .rar files, you could just play a different sound file.) I'm sure that you could prob add a hundred more options to this list if you really wanted to.

Anyway I enjoyed hearing all the hits to my different sites this weekend and thought that you might like to as well.


sound playing lib.
namespace YetAnotherDeveloper.Common.SoundUtility
{

    public
sealed class Player
    {
        private
Player() { }

        public
static void PlaySound(string filePath)
        {
            SoundPlayer player =
new SoundPlayer();
            player.SoundLocation = filePath;
            player.Play();
        }

    }

}


simple http module example.
namespace YetAnotherDeveloper.HttpModules
{
    public
class PlaySoundModule : IHttpModule
    {
        public
void Dispose() { }  

        //Tap into the events.

        public
void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(context_BeginRequest);
         }

         void context_BeginRequest(object sender, EventArgs e)
        {
            YetAnotherDeveloper.Common.SoundUtility.Player.PlaySound(@"C:\Sounds\PageLoad.wav");
        }
    }
}


Modified webconfig to include this module in its pipeline.
<httpModules>
     <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    < add name="PlaySoundModule" type="YetAnotherDeveloper.HttpModules.PlaySoundModule, YetAnotherDeveloper.HttpModules"/>
</httpModules>

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

Development | .Net | Projects

My C# Quine

by joey.westcott 20. January 2008 10:51

I was just dorking it up on the net today and I found an old topic that I haven't thought about in a long time. 

The Quine: (wikipedia)
In short it is a program in which the output or result of the code is the output of the program itself.  So it really just is a program that's only goal is to output the source code of the program.  Many find it "fun" to see how short of a program they can create, for this reason most will leave out formatting including return/line breaks or anything else that is not required for the program to function.

After a little search on the topic I ran into this website that had an example of quines for a ton of different programming languages, but I didn't see any for C# or for that matter none for any .Net languages.  This is probably because the site is old and has not been updated in a long time.  So as I started to type in google "C# quine" I stopped myself and decided that I would just write my own... so I did.  As you can tell I didn't aim for the shortest possible quine, but this being my first run at this I just decided to keep it simple. Maybe I will redo this making the shortest one that I can.

First I'll show you the program with all the nice formatting that you are used to with Visual Studio, I have removed the formatting because I didn't want to include it in the output of the program.  I did include it at first and it was working just fine but it adds a lot of more junk that is just really not needed.

Code after the break
More...

Currently rated 4.7 by 3 people

  • Currently 4.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development

How to remove rogue/zombie workspaces from TeamServer

by joey.westcott 12. December 2007 17:49


When I started my new job I needed to setup my visual studio and map all of my projects to my workspace. But when I attemped to map a project from teamserver to my local box, I got an error stating that this computer already has a workspace with that path in it.  At first I didn't really understand how this could happen because my computer was just F&R'ed (formated and reinstalled), but after a few minutes I realized that this computer probably had the same name as it did before I got there.  The person who used this computer left the company before I inherited it and left his workspaces on the server. After doing some digging around the web, I found a set of commands that would allow me to verify workspaces mapped to this computer and remove them if needed-- and because all of this information is stored on the server, reinstalling the client had no effect on it.

Here is how it all played out... the sections in red are the commands I used.

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Development

Using C# to dynamically change virtual directories in IIS

by joey.westcott 22. November 2007 19:51

At work I have a need to change where a virtual direcorty is mapped in IIS.  So being the lazy developer that I am, I wrote a program that helps me take care of this.  Its a simple application that runs in the system tray and allows the remapping of the virtual directory with a couple of clicks.  I have created a page that I will try to keep updated when and if things change with it.  The source code should be posted by the end of the weekend if anyone desires to have a look at it.

This program will create and delete an IIS virtual directory as needed in C#.   

More details here Virtual Directory Manager

Currently rated 4.0 by 5 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Development | .Net | Projects

SMTP Grey Listing to get rid of most spam

by joey.westcott 17. November 2007 06:32

I have been running my own mail server for about 6 years or so and it took almost 5 years for me to start getting spam on most of my accounts.  The thing about spam is that it really never decreases, you continue to get more and more and more and they never take you off the list, no matter what you do.  I have tried a few tricks to attempt to get removed from a few lists but really nothing works.  For the last 6 months i almost feared my inbox and would notice that i checked it less and less each week, this is really not a viable option because i was getting ~100 spams a day.  I know that for most people that’s not really a huge number but i have had almost zero filtering on my inbox for over 5 years and all was great.  So after talking to one of my buddies, who also run a mail server as well, he told me about the concept of greylisting and how it works... i will not drive into the details of how it works but here is the info

More...

Currently rated 2.0 by 1 people

  • Currently 2/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Microsoft case study on Performance Point

by joey.westcott 15. November 2007 21:21
A little while back while i was working for Skanska USA Building Inc; Skanska had been working with MS to design and blueprint an architecture on how they could leverage its newest BI tools, Performance point.  Microsoft saw our application of the tools and decided to do a case study and video to be displayed at the global launch of Performance Point.  They sent in a film crew that shot video a couple managers and a few other members of the IT staff, i just happen to be one of the few that managed to sneak in for a few scenes.  While i really had no role in the implementation of Performance Point i do still enjoy being in a case study / video on MS website. 

Links to the video and case study:
Case Study (video link also in the top right-hand corner)
Video

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Work

First Thoughts on BlogEngine.Net

by joey.westcott 29. September 2007 19:00

Well i'm just getting into blogging and i thought that i would take a quick eval of all the different .Net blog packages.  I'm not sure why but for some reason i have ended up on BlogEngine.Net.  I have installed and looked that the following packages; Community Server, DasBlog, Subtext and BlogEngine.   To tell the truth i think that i like Community Server the best out of all of them, but i'm not sure that i want to install the 9000 features that come with it.  I do like the design and size of the BlogEngine but it leaves a few features that can NOT be stored in the db and that is a big negative, but will prob be fixed in up coming versions.   

With all of this said i'm going to be giving BlogEngine a try and perhaps i will write some code to get all features in the db myself.  we shall see if i stick with it or move over to one of the other blog packages.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen