Blog posts


  • Remove in javascript string

    November 02, 2009 | Tags: Javascript, Regular expressions, Nils, Snippet
    Yet another extension to the String object in Javascript submitted by Nils Forsman. This one adds the function of removing a part of a string, given a startposition and the length of the part to remove:
    //A - Startindex
    //B - Length
    String.prototype.remove = function(A, B) {
    var s = '';
    if (A > 0)
    s = this.substring(0, A);
    if (A + B < this.length)
    s += this.substring(A + B, this.length);
    return s;
    };
    And some test code:
    var test = "test string test ";
    alert(test);
    var result = test.remove(12,3);
    alert(result);

  • Extend String with trim functions

    November 02, 2009 | Tags: Javascript, Regular expressions, Nils, Snippet
    This is a neat Javascript extension to the String object contributed by Nils Forsman.

    Here's the code that adds trim, ltrim and rtrim to the String object:
    String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, '');
    };

    String.prototype.ltrim = function() {
    return this.replace(/^\s*/g, '');
    };

    String.prototype.rtrim = function() {
    return this.replace(/\s*$/g, '');
    };
    And a little code snippet to test the above functions:
    var testString = " test ";
    testString = testString .trim();
    alert("#" + testString + "#");

  • C# image handling library released

    October 24, 2009 | Tags: Image Library, ASP.NET, Open source, C#
    The first release of Image Library, an open-source C# library to ease common image handling tasks, has just been released. Tutorials on how this library can ease your everyday image handling will follow on this blogg, so stay tuned.

    Download ImageLibrary 1.0 source

    Image library project at Google Code



  • Flash won't include ASP.NET authentication when posting

    October 21, 2009 | Tags: Actionscript, ASP.NET, AS3, Flash
    Ever wanted to use a Flash application posting to your ASP.NET pages, for instance a multiple upload component, and at the same time ensure that the poster is authenticated? This works fine without any additional work in Internet Explorer, but any other browser will fail. This is because Flash won't inherit the cookies from the ASP.NET page it runs at. Thus loosing sessions and authentication.

    The solution is pretty easy to implement. First of all, you cannot have the pages you post to behind authentication in the web.config. You need to do all authentication manually.

    First of all you need to pass a variable containing encrypted user data to the Flash and then post it together with whatever you are posting.
    string userData;

    if(User.Identity.IsAuthenticated) {
    userData = FormsAuthentication.Encrypt(((FormsIdentity)User.Identity).Ticket);
    }

    You pass userData to your Flash and then post it to the server where you use it to authenticate the call:
    string encrypted = Request.QueryString["UserData"];
    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(encrypted);

    if (!ticket.Expired) {
    // The user is authenticated
    // Do your stuff here..
    }

  • Windows XP SP3 upgrade problem

    October 20, 2009 | Tags: XP, Windows, SP, Troubleshooting
    I had some problem upgrading my old Windows XP2 machine to XP3 today. Recieving error messages such as:
    Service Pack 3 setup error. Access is denied.
    Service Pack 3 setup error. Service Pack installation did not complete.
    Service Pack 3 Setup could not backup registry value HKCR\.wdp,\Content Type\' 5: Access is denied.

    Here is the solution:
    • Download and install the SubInACL.exe file from Microsoft
    • Create a .bat file with the following content:
      cd /d "%ProgramFiles%\Windows Resource Kits\Tools"
      subinacl /subkeyreg HKEY_LOCAL_MACHINE /grant=administrators=f /grant=system=f
      subinacl /subkeyreg HKEY_CURRENT_USER /grant=administrators=f /grant=system=f
      subinacl /subkeyreg HKEY_CLASSES_ROOT /grant=administrators=f /grant=system=f
      subinacl /subdirectories %SystemDrive% /grant=administrators=f /grant=system=f
      subinacl /subdirectories %windir%\*.* /grant=administrators=f /grant=system=f
      secedit /configure /cfg %windir%\inf\defltbase.inf /db defltbase.sdb /verbose
    • Run the bat file. Restart when it's done and try install SP3

    Notice! The script above is for the English version of Windows (where the admin group is named Administrators. If you run this in localized Windows XP you'll end up with something like this when you run the script:
    LookupAccountName : C:\windows\*.*:administrators 1337 Detta säkerhets-ID har felaktig struktur.
    Last Syntax Error:WARNING : /grant=administrators=f : Error when checking arguments
    Change all occurences in the script above from grant=administrators to grant=administratörer or whatever you admin group is named. If you need to use national characters in the group name use Edit from the command prompt in order to get proper encoding.