Divis Blog

Just another geeks blog.

Center content on page

clock January 31, 2008 10:47 by author Divi

One day after another I'm having the problem of centering content in the middle of a web-page.

My default way was to enclose the whole page in <center>-tags and put matching content into it - but there're some problems with that.

But from time to time there has been some kind of solution using the "margin"-style-property. The problem: Sometimes it worked - but sometimes it didn't - here it is how you have to do it:

margin:0 auto

With this combination you tell the page "take care of the distance of the content on the left and the right side, so that they match each other.".

Explanation: The first value combines the properties margin-top and -bottom, while the second value combines the -left and -right values.

To get that working there's only one very important thing you have to remember. If you use only this property, the browser will take ALL THE PLACE IT GETS - and that means that it will just fill the whole page with the content and say "ok - space filled - no margin needed". To prevent this you have to set a specific width for the content of the page:

width: Xpx (X = numeric value for the content width)

If you use both style-properties in the tag of the main-content element, it will center automatically (no matter how wide the window is).

 

AutoMargin

 

Hint: If you're working with the <center>-tag - that also works great - you only have to align the content manually again (e.g. if you don't want the text to be centered, you have to say "text-align:left".

Be the first to rate this post

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


CryptographicException

clock January 21, 2008 18:34 by author Divi

Because I hit that error today for the second time (the first time appeared some weeks ago), I thought I just should write it down to not forget it again:

If you get the error messages "Bad Key" or "Invalid handle" in relation to any kind of "System.Security.Cryptography.CryptographicException", you should at first check the write/read-permission of the private-key-file of the certificate - and in the second step, if it contains all required values for our intention (Because you can't do everything with every certificate).

 

My problem: I tried to use an X.509 certificate to sign a Saml-token. Foolishly there were errors on several places, which a catch-block (in combination with a not working logger) hid, so that I needed a lot of time to search for the reason.

Both errors appeared while serializing the token.

 

Two problems and their solution:

Problem 1 - "Invalid handle": This error appeared, if the script couldn't access the private-key file of the certificate. The user "NETWORK SERVICE" needs at least read-permission for this file.

How can I find the private-key file? There's a nice tool collection, created by Microsoft, called the WSE "Web Service Enhancements"... the version, which is, I guess, the current one, is 3.0 - even if most of the results show 2.0, if you search for them with Google.

This collection contains a tool named "WSE X.509 Certificate Tool", with which you can simply select the right values in the two dropdown lists and open a filtered list of all found certificates by hitting the button. As soon as you open a certificate, you can see all information about it. This is the view of one of my test-certificates, which I created myself.

image

At the bottom of the window, you can find a button labeled "View Private Key File Properties". If you click that button, it displays the normal Windows-file dialog for the specified private-key file. In the tab "Security" you can now set the permissions for that file (in our case "NETWORK SERVICE"). As soon as the script is able to read the file, the "invalid handle" message disappears. 

 

Problem 2 - "Bad key": Who is able to read, has an advantage (german saying):

image

As soon as the one input field (Image 1) is replaced with three single input fields (Image 2), the description text on the right changes. It sais: "If the extension is not present, three values will be shown[...]". If I would have read that the first time I tried it, I would have saved much time, because the certificate I bough simply hasn't had the so callend "Subject Key Identifier", which is required for signing the token. As soon as the certificate contains the SKI, you won't get the error message anymore.

 

You can find the WSE tools on the Microsoft-download-page.

 

One last hint I got for you: If you want to check your software against certificates, you can create your own certificates, containing all combinations of rights. There's a nice tool from EldoS which is called "Crypto4™ PKI". It's commercial, but a 30-day trial version can also create nice certificates (for a specific time) ;-).

Currently rated 3.5 by 2 people

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


Kane and Lynch installer

clock January 20, 2008 15:00 by author Divi

After I've heard of "Kane and Lynch" (and just wanted some dark humor), I thought: "Hey - you could try the demo, which is laying around on your desktop for the last days." ... I really had to smile a little bit, as the installer looked as follows:

 

KaneAndLynchInstaller

 

Obviously there was missing a localisation file I thought and tried to click through the well-known mechanics. Unfortunately this try also failed, after I selected the path to install, because there appears an error message, which closes the wizard. Unfortunately I couldn't read anything so I was not able to install that game.

Be the first to rate this post

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


Outlook-Odyssey

clock January 19, 2008 17:11 by author Divi

As I already told you some days ago, I've bought the Office package. Full of anticipation to not get my mails anymore through the web interface but to just open my Outlook, I opened it and selected "Exchange" as mail server type. Obviously the biggest fault I could do :-D 

After I entered all required information for connecting to our Exchange server, my Outlook told me that they couldn't be verified ... Pity ;-) ... but the best joke came after that: Our admin had a good advice for me: First create another account and then set up the Exchange account manually in the configuration menu ... said - tried - failed.

The problem: Outlook offered the following options after reopening it:

1.) Enter valid account information for the Exchange (see above: that didn't work)

2.) Cancel

So I clicked "Cancel" to enter an alternative mailing server as primary account ... but ... hmm ... obviously the "Cancel" button forced Outlook not to go back one step to choose another server but to close ... Hard luck. Outlook wanted me to enter valid data for an Exchange accoutn and NOTHING ELSE!

 

So I thought: There must be any way out and started searching my registry for the name of the Exchange server. I found it on two places. One of them was the browser history (from the web interface) - the other one was at:

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\<username>\13dbb0c8aa05101a9bb000aa002fc45a

First first try was, who'd have guessed, to clear that value... didn't work. So I simply deleted the whole key ... FAULT :-D!

After I started Outlook again, I got the following miraculous message:

MessagingServiceError

(You don't have the current version of the Microsoft Exchange-Message service. Please Create an profile first.)

Hmm ... ok - attempt failed - it was late - I haven't had a backup ... so: repair Outlook ... didn't work - deinstall Outlook and install it again - also didn't work ...

Slowly I got a little bit frustrated... Last try: Got the "work"-laptop and searched the key on it (To go the save way I deleted the whole <username>-key and replaced it with the information from the laptop) ... And when I just were destroying my new system, I also copied the whole profile-directory from the Vista directory:

DRIVE:\USER\<username>\AppData\Local\Microsoft\Outlook

En voila - my Outlook started the first time - the Exchange was already configured and all of my mails were already available (only the mails from the shared folders were missing) - and now I can finally write my mails at home :-D. 

Be the first to rate this post

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


Adding MessageInspectors

clock January 17, 2008 01:46 by author Divi

After some time ago noone could explain to me at tutorials.de how to log incoming and outgoing messages in WCF, I thought I should tell share my knowledge about that with you:

WCF offers a configuration for MessageLogging by default. These are the so called "Diagnostics" and absolutely sufficient if you're really just trying to log something. The related article about that you can find at the MSDN.

Unfortunately the logging can't be configured as detailed as I needed it at that time. My task was to store the sent message related to an object, to check wheter the preprocessing wrapper does its job.

After some searching I found the way of the "Extensions". And that works as follows:

You can set the endpoint in the configuration and attach an Endpoint-Behavior::

<endpoint address="ADDRESS" binding="basicHttpBinding" behaviorConfiguration="AttachClientInspector" contract="CONTRACT" />

Therefore a "Behavior" named "AttachClientInspector" needs to be created (Of course you can chose the name yourself). This one would look somewhat look like this:

<endpointBehaviors>
  <behavior name="AttachClientInspector">
    <ClientInspector />
  </behavior>
</endpointBehaviors>

If you're using Visual Studio 2005, just don't wonder why the "ClientInspector"-Tag is beeing marked with the description "...invalid child element". That's just because the VS2005 doesn't recognize the Extension itself. And that's the next step you have to do. The config section "System.ServiceModel" allows subsections named "Bindings", "Behaviors" and "Extensions". Here you can add your "BehaviorExtension":

<behaviorExtensions>
  <add name="ClientInspector " type="CLASSNAME, ASSEMBLYNAME, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>

Of course the CLASSNAME has to point on a specific class, which is qualified for inspecting the message. To make sure that the class is accepted for this, you have to derive it from "System.ServiceModel.Configuration.BehaviorExtensionElement" AND implement "System.ServiceModel.Description.IEndpointBehavior". You have to derive from BehaviorExtensionElement, to use the class as an extension for the behavior. It requires the allocation of BehaviorType, where you can just return the current class via typeof and the method CreateBehavior, where you just have to return an instance of the current class.

public override Type BehaviorType
{
    get { return typeof(CLASSNAME); }
}

protected override object CreateBehavior()
{
    return new CLASSNAME();
}

On the other hand IEndpointBehavior provides the methods which are called, when the extension is executed at runtime. The interesting method for us should be: "ApplyClientBehavior". This method has a parameter "clientRuntime" of the same-named type. Here you can now attach the inspector as follows:

clientRuntime.MessageInspectors.Add(new CUSTOMINSPECTOR());

So... that's the key thing, to call our inspector as soon as the Endpoint is beeing used. Now there's only missing the implementation of the inspector itself. Therefore you have to create a class named CUSTOMINSPECTOR (the uppercase words are just placeholders to demonstrate the relations) and derive it from the type "System.ServiceModel.Dispatcher.IClientMessageInspector". This interface adds two methods. AfterReceiveReply and BeforeSendRequest. The second one awaits a return value of the type "object"... simply write "return null;" into this method and everything works fine.

If you now hit the compile button, everything should build without any problems. Now we have to add the implementation of the inspector. Therefore both methods have parameters of the type "System.ServiceModel.Channels.Message". In these parameters there's the real message contained.

If you're now trying to use that object, I guess it won't last a long time until you're getting stressed up, because the message-object is getting invalid, as soon as you read any information out of it. Cool, isn't it? ;-)

But you can solve that problem also very easily, because the message-objects contain a method called "CreateBufferedCopy". By calling that method you can create a "buffered copy" of the current message-object:

MessageBuffer bufferedMessage = request.CreateBufferedCopy(request.ToString().Length);

(Here's the message-object "request". In the "AfterReceiveReply" the object is called "reply".)

 

You can modify the "buffered copy" as often as you want and create a message object again after your analysis has finished:

 

request = bufferedMessage.CreateMessage();

(And as already told - again: The parameter of the reply-method is "reply". The object which is filled here, has to be the same as passed to the current method.)

 

All you have to know about it is - you've got several ways to analyze the content of the message:

1.) You can create a XPathNavigator with the method "CreateNavigator" out of the "bufferedMessage", with which you can analyze the xml itself. Over that you can access the content at any part of the XPathNavigator via its property "InnerXML". This one contains the content of the current node as a plaintext-string.

2.) You can also, as already said before, use ToString on the request object, which will return the content of the message (The envelope).

I wish a lot of fun with that and hope I could help you!

Be the first to rate this post

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


Strange problems with the BlogEngine

clock January 12, 2008 00:53 by author Divi

In any way there're some strange problems with the BlogEngine at the moment ... I already got used to edit them again, as soon as I published them from the live-writer, to remove the "tags:" writing,  but there seems to be also a problem with the IDs, because from time to time the entries seem to be duplicated... Or - much worse: I just got home and the newest entry was gone.

Fortunately the Live-Writer had cached a copy of the entry, so it saved me the time for writing it again.

I'll keep track of that ...

[UPDATE 20.01.2008] It simply seems to be the LiveWriter, because everytime I post anything - and even if i'm instantly changing the page after the post, there're two entries created. I've posted an issue about that on Codeplex.

Be the first to rate this post

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


PC update and party

clock January 12, 2008 00:49 by author Divi

Slowly I'm getting ready. Today my new Office 2007 arrived, which I've had ordered at Amazon. On my work-pc I was already used to have it installed, but at home I haven't had it at hand as fast as I wanted. We've got a really cool concept of variable workplaces: Everyone of us got a laptop which he/she can just plug in at a desk next to his/her team colleagues. Unfortunately we have docking stations therefore in the agency, but at home I've got to work on the monitor of the laptop... that's no problem if you "just" want to check your mails or do something else - but a "normal" monitor is irreplaceable, if you want to enjoy the work for a longer time. That's the reason why I'm just gathering all the tools I need to work on my desktop pc at home.

Office2007_thumb1

Nevertheless I've just hired the room I'm always having my parties in. I would have prefered to get the 23.02., but because it was already taken, I decided to shift the party for one week to the 01.03.. And that was very handy as I realized on the next day: So I can have two parties :-D. So if you've ever been on one of my parties - expect your invitation.

Be the first to rate this post

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


Disadvantageous chosen design

clock January 9, 2008 20:35 by author Divi

As we exported a list of voucher codes today, we were shocked, because the list was completely empty. There were only two users that seemed to have entered a code, but there were just the first two digits saved.

We've searched with two persons for about 45 minutes for that bug, because we guessed that there'd be an error while saving the other parts of the code - but despite of which special cases we tried: Everything just worked fine.

After several tests we just went to the page itself and wanted to check if there'd also work everything - but it became obvious: It just was a matter of the design :-D

The place were the voucher codes should be inserted just contained two UNLABELED textboxes. Something like this:

 

The problem that occured, caused by the design, was: The left box was intended to carry the code, while the right box just should take some kind of location information (e.g. a zip or something like that) which allowed every value you entered. Because the voucher code seems to be writte with a dash, or simply just because there was no information about what to insert into the second box, the potential customers splitted the code into both fields. That caused an error in the validation, which could only be resolved, if you deleted both fields. (The reason why the first value was saved is: We didn't clean up the value, if you just entered nothing). Obviously most of the people have tried just stopped trying it after some errors ... or even left the page. That's the reason why we just got the two incomplete codes.

Note: You shouldn't assume that the people which visit your page have the same thoughts as you had when you created the page (after you thought about that for several weeks during the layout period) ;-)

Appendix: Something I forgot to say - the design was created by the customer himself.

Be the first to rate this post

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


Windows Live Writer Support

clock January 8, 2008 19:15 by author Divi

I just though I'd have read something about "Windows Live Writer"-support of the BlogEngine. And I was right - I tried it and: it just worked... :-D

At first I had to think about how to configure it the right way, but it's really enough to just enter the address of the blog (and the login information). If you do so, the live writer gets all the information it needs automatically.

image

One click on "Publish" or "Veröffentlichen" (depending on which pc I'm just using) and the newest entry appears.

The thing I like most is: The Live-Writer skales all the images before uploading ... The only thing I'd now wish for the writer is that it could edit the entries. (Dude - it would be great if there'd be a little microsoft man that would just pass this blog at the moment :-D).

Appendix: Very interesting (and I've tested it several times): If I'm using the Live-Writer, a writing "Tags:" appears directly below the entry ... this one disappears, if you save the entry (doesn't care if you changed anything) again.

Be the first to rate this post

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


Windows-Fonts Dialog

clock January 8, 2008 10:29 by author Divi

The original reason, why I decided to start a blog was the following:

 

You can find this beautiful Window 3.1(?) dialog-box in the Windows-fonts directory of (attention!) Windows-XP (Addition: and Vista :-D). So I was asking me: Was it to much work to replace them? I really had tears-of-joy in my eyes, as, for the first time, I tried to install a font via the menu (all the time before, I just dropped the font-files into that directory - btw.: that just works really fine!).

Be the first to rate this post

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