Computer Magic
Software Design Just For You
 
 

TinyMCE and Ajax Update Panels

July 6th, 2007

For those of you who want to embed a WYSIWIG HTML editor in your web pages, check out TinyMCE. It is a great editor, very customizable.

I recently tried to put the TinyMCE editor into a project that was using Update Panels from the Microsoft Ajax library (previously called Atlas). The TinyMCE editor is a javascript only library that converts text areas to the WYSIWIG editor. This happens at load time.

The trouble I had was when a textarea is displayed after a post back event (e.g. you clicked a link and the editor comes up). The javascript scans the web page when it loads looking for textareas but fails to scan for textareas that are added as a result of an ajax event. The result is that any textareas that are displayed later simply continue to look like a textarea.

The solution is to make sure the init code is called for tinyMCE and tell it manually to add the new textarea.

In your server side code (where ever that is, clicking a page name, etc..) add this code:



ScriptManager.RegisterClientScriptBlock(UpdatePanel1, Me.GetType(), "Init", "tinyMCE.execCommand('mceAddControl', false, '" + txtPage.ClientID + "');", True)

You tell .Net to setup a line of javascript to run when the ajax call completes. This line of javascript is sufficient to tell TinyMCE the name of the new textarea. Notice that I use the ClientID attribute of the text box in question as the name on the client side can be different due to name mangling. Also note, you may have to change the names of the update panel (updatepanel1) and textarea (txtPage) to match your controls. Otherwise, this code should work. Good luck.

Ray Pulsipher

Owner

Computer Magic And Software Design

Medieval Tech Support

June 5th, 2007

Anyone who is a tech will appreciate this. If you aren’t a tech, take a look anyway. Tech support in the dark ages…

http://www.boreme.com/boreme/funny-2007/introducing-the-book-p1.php

IIS 6.0 – Integrated Authentication Issues (NTLM and Kerberos)

December 21st, 2006

Kerberos, for all its many great features and enhancements, can be real pain when it doesn’t work. It is primarily designed for domain centric communications. The upside is that it can enhance your security. The downside is that using Kerberos has the potential to degrade your security (read on before you choke on your own saliva).

The up side:
Kerberos compliments Microsoft’s Domain Server model nicely. It can verify that the connection points are valid, issue access tickets that expire and need to be renewed, and generally make the world a safer place to communicate.

The down side:
Since the Microsoft implementation of Kerberos relies on a domain server, that means that for outside traffic (e.g. web browsing customers) the domain server may need to be exposed to the Internet at large (a domain server is not always required, unless user accounts are domain accounts). If you expose your domain server to the internet to support Kerberos, you have just opened a rather large hole in your network security. Be very careful if you make the choice to do so (hence the possible degradation of security).

Standalone Servers:
Personally, I am running standalone servers (with no domain). This is a common thing for Internet facing servers as they can be placed in a DMZ on your network and your Domain and other critical servers can be placed behind a firewall.

Most of my web traffic is anonymous users coming to my sites. They shouldn’t need domain accounts. The few that do authenticate don’t need domain accounts (local accounts on the web server suffice).

During one of the service packs or updates (not sure which one) an IIS 6.0 server was kicked into a different mode of dealing with integrated authentication (or at least the process of negotiation changed). Integrated authentication is visible when you go to a web site and you get the username/password popup (as apposed to typing your username and password into a webpage itself).

After a certain update (again, not sure which one, but sp1 specifically is mentioned in this context at http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/523ae943-5e6a-4200-9103-9808baa00157.mspx?mfr=true) my clients and I could not authenticate to areas of any websites that were protected by integrated authentication. The system was trying to use Kerberos to authenticate and was failing.

The Problem:
Before Kerberos will do anything, it tries to identify both the host and the client. When identifying the host, it looks at the name of the host, and then uses that to look up the users account. You may not know this, but often the website address (e.g. www.cmagic.biz) will not match the name of the computer that the site is running on (e.g. server1.cmagic.biz). Because of this, Kerberos says who the heck is www? I know who server1 is, but I don’t know www (www is identified in the DNS system, but Kerberos needs to be specifically told that it is ok to authenticate users for www). Slight or major differences in the name can mess Kerberos up.

Solution 1:
One option is to add to the list of SPNs (Service Principle Names) that Kerberos can use to authenticate against (by default only the NetBIOS name of the computer is registered). The setspn.exe tool (download at http://www.microsoft.com/reskit ) can be used to add new names to the list. Make sure you add the Fully Qualified Domain Name (FQDN) instead of just the name (e.g. use www.cmagic.biz, not www). If you host multiple sites on your server, you may need to add all possible sites using this tool. There is lots more information on setspn.exe so I will let you find the exact command on your own. Why? Because this isn’t my preferred solution. You can find more information about SPNs here: http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/523ae943-5e6a-4200-9103-9808baa00157.mspx?mfr=true

Solution 2:
I would really rather not deal with the issue of adding SPNs every time I toss up a new site. In addition, I don’t feel the need to use Kerberos when clients connect. The simple solution is to kick IIS back into NTLM mode (the old form of communication). Some may argue about security implications, but NTLM is MUCH more secure than basic authentication which sends your login information clear text for EACH new page requested. If you are really worried about security, you need to install certificates and use SSL to protect your communications regardless of your authentication mechanism.

In this solution, you can either edit the IIS Metabase directly (the file that stores all of its configuration information) or you can use the vbs script called adsutil (located in the Inetpub\Adminscripts folder). You need to add or change the NTAuthenticationProviders property. There is a chance that the property doesn’t exist in IIS 6.0 (it should in IIS 5.0). As such, I prefer to use the adsutil script because it will put it in the right location for me and save me from putting it in the wrong spot.

In IIS 6.0, you can tweak this setting at multiple levels. In IIS 5.0, you can turn this on/off globally. For IIS 6.0 users, you need to find out the ID of the website (the default site is always 1, after that its anyone’s guess). To find the ID, look at the logfile properties and at the bottom of the first tab is the log file folder. You will see something like (w3svc23452523\..). The number is what you need (23452523).

Open a command prompt and change to the Inetpub\Adminscripts directory. Then for IIS 6.0 type (replace [websiteid] with your site number – e.g. 23452523):



cscript adsutil.vbs set w3svc/[websiteid]/root/NTAuthenticationProviders "NTLM"

For IIS 5.0 type:



cscript adsutil.vbs set w3svc/NTAuthenticationProviders "NTLM"

Once that is done, your IIS server should be set to only use NTLM authentication. Doing this caused my issues to go away. You may need to stop/start your website and/or app pool before the changes take effect.

For more information on using adsutil in this manor, go to: http://support.microsoft.com/kb/215383
NOTE: That page talks about turning Kerberos ON rather than OFF. They show changing the NTAuthenticationProviders property to “Negotiate, NTLM” which means: try Kerberos, then fall back on NTLM.

Ray Pulsipher

Owner

Computer Magic And Software Design

ASP .NET 2005 – Image Columns in the DataGridView Control

December 13th, 2006

The first thing I noticed about the newer visual studio (2005) was that many of the automated tools (such as databinding) now worked. This doesn’t mean that it always works flawlessly, but that you can generally make it work. There are enough events and places you can hook into (not to mention writing your own sub classes) that you can generally find a way to get the behavior you are looking for. Unfortunately, this means that using automatic tools can result in you writing 100’s of lines of code (at times enough that you could have written less code if you had done things manually). Once case I came across the other day was with an ImageColumn in the DataGridView control.

My needs didn’t include binding the image directly to a fields (e.g. storing the image in the database). I just wanted a delete image to show up that could be clicked since I chose to hide the row header (that thing that shows the pencil or asterix and takes up about twice as much room as it needs too). First, I use the point and click interface to set the image for that column thinking, wow, this is easy. In true Microsoft style, instead of showing the image I picked, the column completely ignores the image I specify and shows the broken link image instead. My search for a solution began.

I found that by default, the ImageColumn would set itself to the broken link image. Apparently its by design, though I can’t understand why when you explicitly set the image using the GUI tools. There were two main solutions presented for this problem. Neither were satisfactory to me, but I will include them here to be complete (they may be a better fit for you).

The first solution is to set the default NULL style for the ImageColumn before it is rendered. Apparently this will make it use our “default” image rather than the broken image. With this solution, the column is still behaving badly, but its bad behavior happens to align with your wishes now. I would have been fine with this solution (as all rows should have the same image) had I been able to make it work. For me, this didn’t seem to work (still showed the broken image). I am sure this CAN work if you do it right since I found the same solution in several different places.

The second solution is to write your own ImageColumn class and inherit from the existing class. You can override one of the Format events and return your image. While writing your own class and inheriting from the ImageColumn class is a great feature (in fact that ability is one of the reasons that the databinding in .NET 2005 is considered a viable option now) it seem a little overkill. You see, the ImageColumn is supposed to be able to do what we want… show an image in a column! It seems a little excessive to have to go through all that just to get an image to show when the original class was built to do just that.

My solution is to just hook into one of the many events available and assign the image to the column explicitly. This allows you to also handle each row on a case by case basis (for those of you who might want a different image for each row). The article about writing your own class tipped me off. If you inherit the ImageColumn class just to override a formatting method, why not just use the formatting event in the DataGridView control? Below is the code that I use to set my own image.



Private Sub dgMyGrid_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgMyGrid.CellFormatting
If (e.ColumnIndex = 0) Then
e.Value = My.Resources.del_x
End If
End Sub

The event is called for EACH and EVERY cell displayed. Since my delete button is supposed to be in the first column, I use the column index to see if it is at position 0 (the first column). If it is, it must be one of my delete buttons. The 2005 edition of the .NET framework has some great shortcuts under the My namespace. All your resources (in this case my bitmaps) can be easily accessed via the My.Resources object. This make it extremely easy to pull that image and pass it to our ImageColumn.

Microsoft consistently does an excellent job and a terrible job of designing its programming tools. The parts that work, work great. The parts that don’t, are horribly written and often not worth using. This has changed in the .NET framework due to the fact that they have done a good job enabling you as the programmer to fix or code around things that are broken or that don’t have the features you need. Beware though that you don’t get caught up implementing the complicated solutions when there are simpler solutions out there.

Ray Pulsipher

Owner

Computer Magic And Software Design

Slow connections to MySQL Server

November 2nd, 2006

I have an app that connects to a MySQL Server on a different box. Only one connection is created and it is held for the duration of the app. The minimal time it takes to connect to the database server is not that important so while it bothered me, the 2-5 seconds it took to establish that connection wasn’t troubling enough to look into until recently.

I connect directly to the server in question by specifying its IP address (no firewalls in between). Imagine my surprise when I figure out that it is actually DNS lookups causing the problem. No only that, but the DNS lookup that is slowing things down is the lookup for the client connection, not the database server.

It appears that MySQL does a reverse lookup to identify the client box. Why? Think about security in MySQL. You can give permissions to login from a box (by IP or by DNS name). For this to work, MySQL would need to attempt a reverse DNS lookup to properly establish the level of security this client would enjoy. A DNS lookup will try your primary DNS server, then your secondary DNS server, and possibly your tertiary DNS server before failing completely. This can take 3-5 seconds for all the failures before MySQL decides it doesn’t know your name.

One way to fix this is you could setup your DNS server with a reverse lookup entry for the client box so that the reverse lookup would succeed right away. The DNS query would finish quickly instead of waiting for multiple servers to fail.

There is another possible solution that you could implement if you have control of the MySQL server. You could add the following parameter when starting up mysqld:



--skip-name-resolve

This would tell MySQL NOT to lookup the name of connecting clients. The downside to this would be that you could no longer enable permissions for a DNS name (IP Only!).

I added the reverse lookup option and now mine connects so fast I can barely read the message before it moves on.

Ray Pulsipher

Owner

Computer Magic And Software Design


Home | My Blog | Products | Edumed | About Us | Portfolio | Services | Location | Contact Us | Embedded Python | College Courses | Quick Scan | Web Spy | EZ Auction | Web Hosting
This page has been viewed 827137 times.

Copyright © 2005 Computer Magic And Software Design
(360) 417-6844
computermagic@hotmail.com
computer magic