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.8 by 4 people

  • Currently 3.75/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

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 4 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

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

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen