CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Peter's Gekko

public Blog MyNotepad : Imho { }

April 2004 - Posts

  • From index.htm to default.aspx

    A large project of mine consists of a number of web applications. So far everything was tied together with a regular webpage index.htm. As some asp.net functionality was needed there as well it had to become a default.aspx. Firing up the new web project wizard I had forgotten all about the web.config, with all the (many) shared app settings, in the directory. VS hadn't. Politely it asked if it should overwrite the existing web.config. No thank you. This saved me from looking for the backup. Nice feature.

    Peter

  • Vrijmarkt

    The 30th of april is a national holiday in the Netherlands. Besides being out eldest son's birthday it is queens day. Part of the fun is selling your junk without any need of a permit, vrijmarkt translates as free market. This year my family joined in and we had a good time.

    Being a modern guy I'll continue the fun here on the web. For sale:

    • Finnish version of Office 97 (MSDN leftover)
    • Windows 2/386 on original disks. 5.25 drive not included
    • DS DD 5.25 drive. One head broken.. you can still use it to read single side disks...

    And so one.

    Quote of the day : “Oranje boven. maar boven Groningen gaat niets”. Full clip here. RealPlayer only.

    Enjoy your weekend.

    Peter

     

  • Wikis on the dotnetjunkies ?

    I'm not deep into wiki's at all. The most things I had seen were more or less a kind of chicken-shack, noisy and chaotic. But the interop wiki several people have blogged about is dramatically changing my mind. In the last months I've posted some tips which worked on my (customers) machine to solve common problems like fixing an asp.net installation or getting Crystal to work. These posts keep on attracting loads of comments. A lot with many more usefull tips how to get the problems fixed on other machines as well.

    What I see is people starting conversations in the comments to my original posts and others start asking about related problems. Instead of me updating my posts again and again (or comment that I just don't know either), isn't this what wikis are all about ? Would it be an idea to start them on the dnj ?

    Peter

  • Good meeting

    Yesterday some 60 developers joined for a meeting of DotNed. The presentations were quite diverse

    Hassan Fadili kicked of with a general introduction on platform tot platform communication and the role of design patterns therein. Hassan is a very faithfull DotNed visitor, this time he was on the other side of the beamer. Nervous as hell and plagued by (temporary) crutches he did a flaming talk. Good guy !

    We were ready to see some real .net/java interaction in the second part of the presentation where his collegue Stephan Smetsers demonstrated the model-view-controler pattern. He did this in a Delphi 8 windows app which did not cross any boundaries at all. In the last minute of his part it became clear that the controller component he was demonstrating was not part of Delphi 8 but his own creation. It would have been nice to have heard some more on how he had created that. Chance missed.

    In the second presentation Sander van de Velde showed us the Borland Enterprise Core Objects in Delphi 8. Something comparable to objectspaces. I was very much charmed by Sander's style of presenting : clear, easy going and informative. After an introduction to model driven development, taking it as broad as possible, he did a demo on using ECO in Delphi 8. I was a little less convinced of the usability of ECO itself. It is very hard to use in a true multi-tier scenario and is a vendor lock in down to the database itself. ECO does a lot of fiddling with the databse making it hard to build another app against it without using ECO.

    The first glimpse of Visual studio was not untill the third presentation. Marc van Gulik of the hosting Deco ICT solutions did a very good talk on .net remoting. (No picture available) In a couple one liner demo's he very cleary demonstrated diffences like client side activated versus server side activated. Just quality.

    Peer to peer at dotned is always great thanks to the diversity of the visitors. Many of them have or had something with Delphi leading to interesting discussions. Delphi (8) for .net is a now reality but will it keep the tool in the mainstream ? It comes with a set of tools (like ECO) but how everything is integrated is another question. The tools were bought which still clearly shows through. For instance, the database key fields generated by ECO are named BoldID. BoldSoft was the creator of the tool. At the same time a lot of the Delphi developers were laid off. You do need real developers to integrate your tools. Speaking of commerce, another con is the price of Delphi. For the price of one Delphi enterprise licence you can have two years of MSDN universal. But breaking up is hard to do.

    The journey home form a dotned meeting always has a special attraction. Last time I got caught in a blizzard. This time all traffic on the highway was set aside for a an alcohol check. Good ! Dutch traffic is horrible, everything helps. The kind of bumper stickers on my old (but not rusty) Volvo are quite different from the one's Brendan suggests. In Dutch a bumper sticker (bumperklever) is somebody driving just a couple of feet behind, at a speed far over 100 km/hour. That said I hope to survive to see all of you on the next meeting.

    Peter

  • Live at last : the myfone asp.net forum

    It took some trouble but the forum of myfone is live at last. We are using the beta of the asp.net forums which is an open source app still undergoing (big) changes. The myfone site already had a large user database and offers extra functionality to registered users. This led to a conflicting wishlist :

    1. To the users the site and the forum should be one. No separate logins.
    2. The asp.net forum application should be used with as little alterations as possible

    The implementation took quite some research but we have found an easy way :

    1. Comment out the login and logout controls in the user controls of the asp.net forums. The user controls are a skin to the forum code which will not miss the login boxes and buttons.
    2. Transfer the user credentials from the custom application to the forum application using a cookie.
    3. Add a custom login and logout form to the forum app. These handle the cookie and redirect the request. They never show up.

    And it works. In case you're interested : membership is free. The main site is in Dutch but the forum is in English. After all it is the beta forum straight from the zip.

    Peter

     

  • Don't forget the Ned

    Hey you Dutchies. Don't forget to come tomorrow (22nd of april) to the meeting of the dotned user group. See you there.

    Peter

  • Spam, .NET and a Windows service

    A new article with this title is up on the sdgn site. It's a bit of cookbook recipe how to build, install and debug a Windows service. The functionality of the service uses devmail to read and write email.

    Peter

  • XML-RPC (and Dutch ZIP codes)

    Cendris is offering a (paid) web service to validate Dutch ZIP codes. A bump in using it is that it does not offer goodies like wsdl like we are used to in the .NET implementation of web services. Cendris uses classical XML-RPC. But you don't have to (dis-)assemble the request and responses yourself. Charles Cook has a nice tool available which will (amongst other things) create proxies for the XML-RPC on the fly in your code. It comes with clear examples and consists of one assembly. You define your proxy by declaring an interface describing it. You define the in and out parameters by declaring structs describing them.

    It took me some time to find the declarations for the Cendris ZIP services. The main problem was the Cendris documentation. All method and param names are case-sensitive and in the docs are some casing errors. The docs do contains full examples of a request and response. But these are in non-indented XML and are rendered very badly in the PDF. So I'll reproduce my full declarations here

    using System;
    using CookComputing.XmlRpc;

    struct CendrisPostCodeUit
    {
       public string
    straatnaam;
       public string
    huisnummer;
       public string
    postcode;
       public string
    woonplaats;
       public string
    netnummer;
       public string
    status;
    }

    struct CendrisAdresUit
    {
       public string
    straatnaam;
       public string
    huisnummer;
       public string
    postcode;
       public string
    woonplaats;
       public string
    netnummer;
       public string
    match;
    }

    struct CendrisPostCodeIn
    {
       public string
    username;
       public string
    password;
       public string
    postcode;
       public string
    huisnummer;
    }

    struct CendrisCheckAdresIn
    {
       public string
    username;
       public string
    password;
       public string
    straatnaam;
       public string
    huisnummer;
       public string
    woonplaats;
    }

    [XmlRpcUrl(http://www.dataonline.nl/adresxpress/server/adresxpress_server.php)]
    interface
    IcendrisPostcode
    {
       [XmlRpcMethod("adresxpress.postcode"
    )]
      CendrisPostCodeUit PostCode(CendrisPostCodeIn request);

       [XmlRpcMethod("adresxpress.checkadres")]
       CendrisAdresUit[] CheckAdres(CendrisCheckAdresIn request);

    }

    You use the service by creating a proxy, typecasting it to the interface and then call the interfaces methods

    IcendrisPostcode cendris = (IcendrisPostcode) XmlRpcProxyGen.Create(typeof(IcendrisPostcode));

    CendrisPostCodeIn request;
    request.username = "yourusername"
    ;
    request.password = "yourpwd"
    ;
    request.postcode = textBoxPC.Text;
    request.huisnummer = textBoxNummer.Text;

    try
    {
       CendrisPostCodeUit res = cendris.PostCode(request);
       textBoxStraat.Text = res.straatnaam;
       textBoxNummer.Text = res.huisnummer;
       textBoxPC.Text = res.postcode;
       textBoxPlaats.Text = res.woonplaats;
    }
    catch
    (Exception ex)
    {

       MessageBox.Show(ex.Message);
    }

    The service not only checks the zipcode but also transforms all address data to (NEN) standard notation.

    It took some fiddling, but now its working like a snap. Who needs pv ?

    Peter

  • Transfering data between webapps using a cookie

    At this moment I am working on coupling two different applications. A custom one and the asp.net beta forums. What I want to do is use an own user database to authenticate users in the forum app. The asp.net forums use forms authentication to log on users. In a previous post I demonstrated how to work with forms authentication without popping up a login dialog. The next step was to bring the user credentials from my app to the forum.

    There are several ways to store state in a web app:

    • Viewstate. Limited to one and the same webpage.
    • Application object. Limited to an instance (in a web-farm or garder there are multiple instances) of the application
    • Session. Limited to the session of one application. At first sight I had expected the state to be shared by multiple applications within one session. Which is not the case.
    • Cookies.  Limited to one and the same webuser. Which is what I need.

    There are far more way to handle this. James Beine suggested a webservice to manage state. Which would be perfect but somewhat of an overkill for this scenario.

    The idea is to set up the cookie when the user logs into the app.

    HttpCookie ck = new HttpCookie("MyCookie");
    ck.Values.Add("userName", TextBox1.Text);
    ck.Values.Add("pwd", TextBox2.Text);
    ck.Values.Add(
    "email", TextBox3.Text);
    Response.Cookies.Add(ck);

    The authentication page used in the forum will check for this cookie.

    const string myCookieName = "MyCookie";

    System.Web.HttpCookie ck = Request.Cookies[myCookieName];

    if (ck != null)
    {
        forumsUser = new
    AspNetForums.Components.User();
        forumsUser.Username = ck.Values["userName"
    ];
        forumsUser.Password = ck.Values["pwd"
    ];
        forumsUser.Email = ck.Values["email"
    ];
        forumsUser.IsAnonymous = false;

        Response.Cookies[myCookieName].Expires = DateTime.Now.AddYears(-1);
        Request.Cookies[myCookieName].Expires = DateTime.Now.AddYears(-1);

        if (AspNetForums.Users.ValidUser(forumsUser) == AspNetForums.Enumerations.LoginUserStatus.Success)
        {
           System.Web.Security.FormsAuthentication.SetAuthCookie(forumsUser.Username, false);
           Page.Response.Redirect(Request.QueryString["ReturnUrl"]);
           Page.Response.End();
        }

    }

    This is some condensed demo code, I'll leave the full story for a next time. Here I'll concentrate on the cookie. Once used the cookie should be deleted, else the user would be granted access to the forum without ever rechecking his credentials again. To delete the cookie I experienced some difficulties. This is what I think is going on, please comment if I'm wrong. I'll be most happy to update.

    • The cookies collection of request and response have a remove method. This method does not seem to work ?
    • In a second approach I tried to set the expiration datetime of the cookie at cookie creation. Which works fine when you're working on one machine (with a localhost) but is a disaster in real life. The expiration time set is using the server's clock. Whether the cookie is sent again by the browser is determined by the browsers clock. These clocks are most likely to be (totaly) out of sync.
    • When you set the expiration of an existing cookie to sometime long ago, the cookie will be gone
    • You have to set the expiration of the cookie in the response and in the request. Else the non-expired cookie will be copied from the request again ?

    How cookies are exactly handled in the cycle of processing a request is not completely clear to me. Interesting is to see what happens if the request gets redirected. Suppose you set a cookie, fill it with some value and redirect to another page from code. While handling that page you will see that the cookie is set. But the values contained are all empty. I conclude that a cookie can not be consumed until the next roundtrip.

    Peter

  • System.DBNull.Value != null

    Spent the most of easter digging through heaps of sql. So here's another “in-stinker” which almost had me fooled again.

    Inside of a component I'm not afraid to work directly with sqlcommands. Setting up a datadapter and a dataset would be an overkill when the database will return just a scalar value. The result returned by the ExecuteScalar method can be somewhat misleading at first sight. Take this code

    public string CustomerName(int custId)
    {
       SqlCommand cmd = new SqlCommand(string.Format("SELECT Name FROM Customers WHERE idCust = {0}"
    , custId), sqlConnectionToSchaakBondDB);
       object
    result = cmd.ExecuteScalar();

       if (result == null)
          return "Customer not found"
    ;
       if
    (result == System.DBNull.Value)
          return "Customer found but name is null"
    ;
       return (string) result;

    Testing the result only against null could give a quite misleading result. In the second case the method does return a value but the content of this value is null. Which is not the same as not returning a value at all.

    Peter

     

  • Where it's @ when addressing sql parameters from code.

    Speaking of SQL. Take this sql query in a datadapter

    SELECT Name, Street FROM Customer WHERE id = @idCust

    The @ in front of idCust indicate idCust is a paramater. You can access these parameters from code. Being a bad or lazy typer (I'm both) it's tempting to do this by number.

    sqlDataAdapter.SelectCommand.Parameters[0].Value = 12;

    In maintanable code it should be done by name

    sqlDataAdapter.SelectCommand.Parameters[“@idCust“].Value = 12;

    The @ is part of the parameter's name. My first guess would have been different.

    Peter

     

     

  • sa ? Sharks Anonymous !

    In the dark years of last century the letters sa, standing for one of the nazi groups, were bad. They still are banned form Dutch car plates. As not to confront people with the dreaded letters.

    IT has given the two-letter combination a new chance as being the name of your favaurite sql user. To be found in many a web.config.

    But for me, since Finding Nemo, sa now stands for Sharks Anonymous.

    Peter

  • The scope of the session object (where have my objects gone ?)

    You can use the session object to store things you need in other places of your web-app. With the many assemblies which make an app it is sometimes a little puzzling where your session objects can be reached and where they are unavailable. When your code enters another assembly (like a classlib) your objects will be there. But when your app enters a page in another webapp (that is another virtual IIS directory) your session objects are unreachable. It does make sense when I start thinking about it (imagine some other alien app fiddling with your session objects..). But it had me pulling my hair for some time. (Yes you may laugh..)

    When you want to exchange data with another webapplication you can use a cookie. The bad thing about that is that it takes some more effort to administer those (don't forget to remove), cookies can only store string values and cookies travel over the wire from and to the client. But they do work.

    Peter

     

  • CoCreateGuid .net style

    For an app I needed some GUID's at runtime. In the COM days I  used the CoCreateGuid for that. In .NET it is much simpler, it is even so simple  I overlooked it and spent far to long looking for a way to import the COM stuff in my code. So let me share what I found in the help file.

    The Guid class has a static meber which will get me my guid:

    aanmelding.ReplyGuid = System.Guid.NewGuid().ToString();

    This one-liner generates a new guid and puts it in string format into my field. That's all.

    Peter

  • Apple is no Aprils fool

    Did you know that the Apple company was founded the 1st of april in 1976 ? I didn't, but our local newspaper had a story (in Dutch) on the birth of the personal computer. The story started nice but the expert carted in stated that Apple was the first computer to bring windows to the masses (which is true) and Microsoft copied the idea. Which is not true, every geek should know it was the Xerox Palo Alto lab where the ideas were born, both Apple and MS got their inspiration there. This was a also debate some time ago when the trashcan was introduced to Windows (It always has been a part of the Apple desktop). In the heat of that battle somebody made the suggestion to hit the streets and stamp “Copyright of the Apple Cooperation” on every trash can you could find.

    Anyway, it looks like the same old story. A good idea, several companies implementing it, MS turning it into a commercial succes after which the fight gets muddy. If a “monopoly” doesn't work, try “stole the idea”. Making everybody look like April's fool.

    Peter

More Posts