Jeff Widmer's Blog

ASP.NET, ASP.NET MVC, C#, VB.NET, IIS7, Windows Forms, VB6, ASP 3.0

  • StackOverflow to Google Index in 30 minutes

    This is pretty amazing.  I asked a question on StackOverflow and 30 minutes later (while I was still trying to find the answer on my own) I found my question indexed in Google’s search results.  WOW!

    image

    image

    Bing didn’t have my StackOverflow question… but it did have an answer for me.

    +1 for Google getting my StackOverflow question indexed so fast.
    +10 for Bing getting me the answer.

    Technorati Tags: ,,


  • jQuery: How to check if button is disabled

    You can use jQuery to trigger a button click from the client.  In this certain situation, I needed to make sure the button was not disabled prior to clicking.  In jQuery you can use the “is” function to check if the button is disabled like this:

    <script type="text/javascript">
        $(document).ready(function() {
        if ($('#StartButton').is(':disabled') == false) {
                $('#StartButton').click();
            }
        });
    </script>

     

    Technorati Tags:


  • Changing up how my Someday/Maybes are organized

    I am a big fan of Getting Things Done (GTD) and highly recommend the GTD book and the methodology to everyone and anyone. 

    I do not consider myself a GTD Black belt yet but I am continually progressing and getting better and better at GTD each and everyday.  One of the areas of GTD that I consider to be my weakest is the Organize part of GTD.  I tend to resist moving projects and next actions that are truly someday/maybes into my someday/maybe list.  This is because my someday/maybe list has become so large that I do not review it regularly and no longer is it a trusted part of my GTD system.

    But I am also a big fan of keeping things flat.  I want to keep the overhead associated with running a GTD system at a minimum and having everything flat is a huge win for me in this area.  Up until now I had a single someday/maybe section (I use OneNote) for all of my someday/maybes but it definitely has become overwhelming and I am resisting putting things into the blackhole that is my someday/maybe list.

    I am going to try separating them into the various roles that I have:

    • Developer
    • Husband
    • Father
    • Homeowner
    • Entrepreneur

    image

    I will see if this will allow me to keep my Next Action and Project list clean by feeling completely comfortable moving a stale item into my someday/maybe list (now that I can review these regularly… something I was not doing to my someday/maybes which is why I resisted moving items there in the first place).

    Technorati Tags: ,


  • Amazon Same Day Shipping

    Back in October I heard that Amazon was introducing same day shipping delivery for some cities. Today I received an email for being an Amazon Prime member reminding me that Amazon has the ability to deliver an item to me within the same day.  But what is really amazing is the cut-off times; in Seattle you can order an item up to 1PM and get it delivered to you that same day:

    image

    That is amazing!  Talk about reducing the friction in buying… Amazon is an expert!  Just ask me how many items I bought for Christmas through Amazon Prime just because I get free two-day shipping.

    Technorati Tags:


  • Where to find the Subversion Binaries (svn.exe)?

    I was setting up CruiseControl.NET for the Vaasnet automated build system and I needed the Subversion binaries.  This is my first project that I had used Subversion for source control and up until now I had just been using TortoiseSVN for interacting with the source control repository. 

    CruiseControl.NET needs the Subversion binaries since this is how it communicates with your Subversion repository (through svn.exe).  Finding just the binaries ended up being a particularly difficult task.  Eventually I figured it out… posting here for anyone else that also runs into this issue:

    1. Start here: Tigris.org – Getting Subversion
    2. Head down to the Windows section and click on the Tigris.org link:
      • image
    3. Look for the latest version MSI installer (at the time this post was written v. 1.6.6)
      • image
      • Name: Setup-Subversion-1.6.6.msi
    4. Run this installation app and you will get svn.exe installed on your machine.
      • On Windows Server 2008 64-bit the default install path will be:
        • C:\Program Files (x86)\Subversion\bin\svn.exe

    Hopefully this will help someone else in the future.

    EDIT (2011-01-25): Alec Taylor found up to date ones here:

    EDIT (2012-01-27):

    See http://nightlybuilds.tortoisesvn.net/  for instructions on the correct folder for the stable release.  The "latest" folder is the nightly build.

    Technorati Tags: ,


  • URL Authorization role service required for IIS7 system.webServer/security/authorization

    Why isn’t IIS7 authorization working in my asp.net website?  I was trying to secure a folder in my asp.net application using the IIS7 system.webServer/security/authorization configuration settings.  In the past you could do this through the ASP.NET configuration by adding an authorization section to the system.web section in your web.config.   But now with IIS7, you can use the new system.webServer/security/authorization section to specify authorization rules.  The benefit of system.webServer authorization over system.web authorization is that the former applies for all requests to that particular location, the latter only protects asp.net requests (requests that come through the asp.net pipeline).

    So, since I am developing this application on IIS7, I wanted to use the new IIS7 system.webServer authorization section to protect a particular folder.  To do this, I added the following section to my web.config file:

    <location path="admin">
      <system.webServer>
        <security>
          <authorization>
            <remove users="*" roles="" verbs="" />
            <add accessType="Allow" users="" roles="administrators" />
          </authorization>
        </security>
      </system.webServer>
    </location>

    and tested the url http://localhost/admin and… it didn’t work.  What should have happened is I should have been redirected to the forms authentication login page, but instead I was served the content under the /admin folder.  Not what I wanted; the /admin folder should now require an authenticated user and the forms authentication identity to be part of the administrators role.

    What is going on?!?!?  Everything looked correct.  I confirmed that IIS authentication was set correctly: anonymous and forms authentication only.  I confirmed that the system.web/authorization section was working.  I tried in multiple browsers to make sure it wasn’t a cookie or a caching issue.  Still I was left scratching my head… why were settings in the IIS7 system.webServer/security/authorization not getting picked up?

    Finally, with the help of Scott Forsyth, I checked the Server Manager IIS Roles that were enabled.  Server Manager > Roles > Web Server (IIS) > Add Role Services

    image

    image

    Notice that the URL Authorization role service is not installed. 

    image

     

    That was it.  IIS7 did not have the role service installed so it was not understanding that section of the web.config file.

    After installing the IIS URL Authorization role service, a request to http://localhost/admin redirected to the forms authentication login page and required a user that was in the administrators role.



  • CruiseControl.NET Configuration Reference

    For some reason it is very difficult for me to find the CruiseControl.NET configuration reference online.  Most of the time I end up on an older reference which is out of date and just not correct. 

    This is the CruiseControl.NET reference that appears to be up-to-date:

    CruiseControl.NET Configuration Reference 
    http://confluence.public.thoughtworks.org/display/CCNET/The+CruiseControl+Configuration+Block

    On the bottom of each page is a list of the children for each configuration block and at the top is the breadcrumb for how far you have drilled down into the tree.

    image

    image

    And then you can view the full CruiseControl.NET configuration hierarchy here.

    This blog post is mostly for me but also, if I am having a tough time finding the reference then I imagine a lot of other people are too.



  • Prevent CruiseControl.NET error “Source control operation failed: Working copy locked svn”

    My CruiseControl.NET build system was running into an error whenever two projects were trying to build at the same time.  Both of these projects try to go out to our subversion source control repository and one will win and the other gets locked out.

    The build will then fail with this type of error:

    ThoughtWorks.CruiseControl.Core.CruiseControlException: Source control operation failed: svn: Working copy 'XXXX' locked svn: run 'svn cleanup' to remove locks (type 'svn help cleanup' for details) .

    To get around this issue you can use the “queue” attribute of the project node:

    image

    Here is the Thoughtworks CruiseControl.NET Project configuration reference section: http://confluence.public.thoughtworks.org/display/CCNET/Project+Configuration+Block

    Originally I did not set a queue value for each project that is built.  The default in this instance is the project name, so each project ends up in its own queue and therefore they will build as soon as possible and cause the locking error.

    From the Thoughtworks reference:

    queue 
    The name of the integration queue that this project will use. By default, each project runs in its own queue. (Added in CCNet 1.3) 

    So by setting the queue for each of the projects to the same value (since all of the projects are related), each of them will wait and build one at a time, resolving the “Source control operation failed: svn: Working copy 'XXXX' locked svn” error.

    Note: You can also set the queuePriority to indicate the order the project should build when it is in the queue.

    This StackOverflow post lead me to this solution: How can I prevent concurrent builds in CruiseControl.NET?



  • Handle the button click event from an ASP.NET ListView control

    Here is how you can handle the event of a button from within an ASP.NET ListView control.

    Add your button to the ListView Template like you would any other control:

    <asp:ListView ItemPlaceholderID="Test" runat="server" ID="ListView1" >
        <ItemTemplate>
            <asp:Button runat="server" Text='<%# Eval("MyProperty") %>' CommandArgument='<%# Eval("MyProperty") %>' /><br />
        </ItemTemplate>
    </asp:ListView>

    image

    And then handle the ListView.ItemCommand event in your code:

    image

    That is really all there is to it.  The ListView will bubble up the Button’s click event to the ListView_ItemCommand event handler and then you can handle it there.  You can also use the CommandArgument property to send button specific data, such as the particular ID of the row or item that the user clicked the button for.

    This call also be used on some of the other databound controls such as the ASP.NET Repeater.

     

    Full Example Code:

    ListViewButtonExample.aspx:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ListViewButtonExample.aspx.cs" Inherits="ListViewButtonExample" %>
    <html>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ListView ItemPlaceholderID="Test" runat="server" ID="ListView1" >
                <LayoutTemplate>
                    <asp:Literal runat="server" ID="Test"></asp:Literal>
                </LayoutTemplate>
                <ItemTemplate>
                    <asp:Literal runat="server" Text='<%# Eval("MyProperty") %>'></asp:Literal>
                    <asp:Button runat="server" Text='<%# Eval("MyProperty") %>' CommandArgument='<%# Eval("MyProperty") %>' /><br />
                </ItemTemplate>
            </asp:ListView>
            <asp:Literal runat="server" ID="Literal1"></asp:Literal>
        </div>
        </form>
    </body>
    </html>

    ListViewButtonExample.aspx.cs:
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.Security;
    using System.Collections;

    public class MyObject
    {
        public String MyProperty { get; set; }
    }
    public partial class ListViewButtonExample : System.Web.UI.Page
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            ListView1.ItemCommand += new EventHandler<ListViewCommandEventArgs>(ListView1_ItemCommand);
        }

        void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            Literal1.Text = "You clicked the " + (String)e.CommandArgument + " button";
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                List<MyObject> col = new List<MyObject>();
                col.Add(new MyObject { MyProperty = "test 1" });
                col.Add(new MyObject { MyProperty = "test 2" });
                ListView1.DataSource = col;
                ListView1.DataBind();
            }
        }
    }

     

    Technorati Tags: ,


  • IIS7 Search Engine Optimization Toolkit does not like HTML5 Doctype

    The IIS7 Search Engine Optimization (SEO) Toolkit is an awesome tool to review your site and indicate any problems with the html that may cause search engines not to index your website properly.  Check out Scott Guthrie’s post on the IIS7 Search Engine Optimization Toolkit or you can download it from the IIS website at the tool’s home: IIS7 SEO Toolkit.

    But I ran into an issue with the tool the other day where it was not returning the proper results.  I ran it against a website I was working on and it only crawled one page and returned results that were just not correct:

    image

    The errors: “The title is missing.”, “The description is missing.”, and “The <h1> tag is missing.” were incorrect since I had all of those on the home page of the site I was testing, but also it was curious that it was not crawling any other urls off of that home page.

    AND the content tab even showed all of these things in the html that the tool had retrieved:

    image

    Eventually I was able to track it down to using the HTML5 Doctype tag:

    <!DOCTYPE html>

    The HTML5 document type is not official yet but I have gone ahead and started using as recommended by many developers but apparently the IIS7 SEO Toolkit does not like this doctype yet.  Temporarily I switched it to another doctype:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

    And the SEO Toolkit worked as expected.  Just a heads up for any other developers that run into this when using HTML5 DOCTYPE.

    UPDATE (2009-12-07):

    Dave Cox added a comment about it not being the HTML5 DOCTYPE per say but the whitespace that comes before it.  Having a line of whitespace AND the HTML5 DOCTYPE causes the IIS7 SEO Toolkit not to read the content correctly.

    Bad:
    image

    Good:
    image

    I am using ASP.NET MVC in this project so that means my master page will look like this; the DOCTYPE declaration on the same line as the Master page directive:

    image