Skip to main content

WSS and audience targeting

If you follow Willy’s blog you would have seen a post mentioning I have been a busy little person recently (if you hadn’t see it you can go here to read it). One of the things about SAArchitect.net is that it does not run on the big boys edition of SharePoint, it actually runs on WSS. However the thing people commonly forget about WSS is that it actually can do everything it’s brother can do, it just does not have all the templates and the fiddly bits out of the box. This means the time/cost/pain to get to the same point as it’s brother is a bit/minor/average/excessively more. One of the fiddly little bits which is missing, is audience targeting. Which I think is super sexy for public web sites, especially when you want to show different things to users who have logged in or and those who haven’t. An example is on the new SAArchitect site when you are logged in it should let you change your password and if you aren’t logged in then it should let you apply or request a forgotten password.

So putting my developer cap on (or at least adjusting it since it doesn’t ever come off) I fired up my trusty copy of Visual Studio. I needed VS as I had decided to solve this using ASP.NET and a web part which does come with WSS, the Content Editor Web Part (CEWP). Utilizing all of the power of Visual Studio 2008, I toiled away to produce my ASP.NET page with a staggering 22 lines of code which looks something like this:

Note: All the code is available in the file at the end of this post.

   1: <%@ Page Language="C#" ContentType="text/xml" %>
   2:  
   3: <%@ Import Namespace="System" %>
   4: <%@ Import Namespace="System.Globalization" %>
   5: <%@ Import Namespace="System.Web.UI" %>
   6: <script language="C#" runat="server">
   7:     protected override void OnPreRender(EventArgs e)
   8:         {
   9:             string result = string.Empty;
  10:             if (Page.User.Identity.IsAuthenticated)
  11:             {
  12:                 result = String.Format(CultureInfo.CurrentCulture, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
  13:                     "<user xmlns=\"http://schemas.saarchitect.net/ajax/2008/09/user\" username=\"{0}\" />", Page.User.Identity.Name);
  14:             }
  15:             else
  16:             {
  17:                 result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
  18:                     "<user xmlns=\"http://schemas.saarchitect.net/ajax/2008/09/user\" username=\"\" />";
  19:             }
  20:             Response.Write(result);
  21:         }
  22: </script>

For those out there looking at that code and thinking it looks a little odd, it could be that the code all goes in the .aspx page itself. No code behind magic or web.configs or app_data folders to weigh this down. At 22 lines of code it’s all very simple: just checking if you are authenticated and if you are it returns an XML fragment with your name in it, and if you aren’t a XML fragment with no name and even a pretty namespace. In reality that could have been smaller like <u a=”0”/> if you aren’t logged in and  <u a=”1”/> if you are, but that isn’t very human readable ;) That single file sits on the WSS site in a document library, which is interesting (at least to me) because SharePoint will not let the code run by default as a way of protecting you from security issues. However if you are smart/brave/stupid enough you can tell SharePoint to let you run it, using the SharePoint web.config. Microsoft has a great article on how to do that over there.

Now that I have the code to tell me if I am logged in or not, I need to hide/show content based on it, which is easily done using the source editing options of the CEWP to plop in a bit of JavaScript. This bit of JavaScript uses a XMLHttpRequest to call the ASP.NET page and gets the result, which I check and based on the result show the relevant content as described below:

   1: <script type="text/javascript">
   2: //Partially from http://www.w3schools.com/XML/xml_http.asp
   3: // Partially from http://en.wikipedia.org/wiki/Xmlhttprequest
   4: // Provide the XMLHttpRequest class for IE 5.x-6.x:
   5: if( typeof XMLHttpRequest == "undefined" ) XMLHttpRequest = function() {
   6:   try { return new ActiveXObject("Msxml2.XMLHTTP.6.0") } catch(e) {}
   7:   try { return new ActiveXObject("Msxml2.XMLHTTP.3.0") } catch(e) {}
   8:   try { return new ActiveXObject("Msxml2.XMLHTTP") } catch(e) {}
   9:   try { return new ActiveXObject("Microsoft.XMLHTTP") } catch(e) {}
  10:   throw new Error( "This browser does not support XMLHttpRequest." )
  11: };
  12:  
  13:  
  14: var xmlhttp;
  15: function loadXMLDoc(url)
  16: {
  17:   xmlhttp = new XMLHttpRequest();
  18:  
  19:   if (xmlhttp != null)
  20:    {
  21:      xmlhttp.onreadystatechange=state_Change;
  22:      xmlhttp.open("GET",url,true);
  23:      xmlhttp.send(null);
  24:    }
  25:    else
  26:    {
  27:      alert("Your browser does not support XMLHTTP.");
  28:    }
  29:  }
  30:   
  31:  function state_Change()
  32:  {
  33:    if (xmlhttp.readyState == 4)
  34:    {// 4 = "loaded"
  35:      if (xmlhttp.status == 200)
  36:      {// 200 = OK
  37:        var username = xmlhttp.responseXML.selectSingleNode('//user').getAttribute('username');
  38:        if (username.length > 0)
  39:        {
  40:          // user logged in
  41:  document.getElementById('resultText').outerHTML = '<P><A href="/memberPages/changepassword.aspx">Change Password</A></P>';
  42:        }
  43:        else
  44:        {
  45:          // anonymous
  46:          document.getElementById('resultText').outerHTML = '<P><A href="/Pages/signup.aspx">Signup</A><BR><A href="/Pages/forgotpassword.aspx">Lost Password</A></P>';
  47:        }
  48:      }
  49:      else
  50:      {
  51:        alert("Problem retrieving XML data");
  52:      }
  53:    }
  54:  }
  55:   
  56:  loadXMLDoc("/Pages/loggedinuser.aspx");
  57:  </script> 
  58:  <span id="resultText"/>
  59:  

Admittedly this is not a solution that the little old lady with the white lunch box will be able to implement while she updates the bridge league site, but this might work just fine for a site about architecture which has a few smart people, a couple of MVP’s and me running around behind it.

You can download the page and the JavaScript in this file: DOWNLOAD

IMPORTANT NOTE: I have posted a follow up article which fixes some issues with this version. For more information see WSS and audience targeting - Part II.

Microsoft CRM Email Troubles

An email asking for help on a problem floated by me and I thought it was an interesting enough one to blog about. First off all I had was the following error message from the MSCRM Exchange router:

#61042 - An error occurred while processing the outgoing e-mail message with subject "CRM ADMIN TEST MAIL CRM:0004015" for SMTP: http://crmserver/tenant/ for delivery through exchangeserver. System.Net.Mail.SmtpException: Mailbox unavailable. The server response was: 5.7.1 Client does not have permissions to send as this sender

The guy asking the question was trying to figure out what was wrong with CRM because that’s where the error was coming from. The problem is that he was looking in the wrong place. If you read the error carefully the last bit is actually the most important: The server response was: 5.7.1 Client does not have permissions to send as this sender

It actually states that the server (not CRM, but Exchange) responded with the client not having permissions to send. This is a fairly common issue and the resolutions fall into one of two options:

  1. The email address in the from can’t be used because you do not have permission to use it (duh) and you merely need to change the address to one you have permission to use.
  2. The second option is to enable SMTP authentication which should give you the permissions to send them mail.

The first tool for anyone using virtualisation

I am a fan of virtualisation, my comments on an earlier post about it being the future should be a give away. As such I have a “few” VHD's around and sometimes I have problems which the out of the box technology can’t cope with. A few of these are:

  1. I sometimes there is some code, or a sample or I need to get a file to fix something which is sitting in the VHD file. The pain here is that to do that you need to boot up the VM, login in to it, find the file and copy the file to the host machine.
  2. As pointed out before I work in a team which does not prescribe to what is the best tool to use. I personally use Hyper-V but that’s me. VirtualPC is used by some people who are running Vista or XP, VMWare is popular with lots of people (duh) and so is Xen, so how do I get my files to them?
  3. Some times I need to test something that runs on a live system so I need a VM of the system.
  4. Other times I want to deploy what I have done on a VM and deploy it to a physical machine.

Well all the above are just plain annoying, but thankfully there is a program called WinImage! (It does come with a 30day full functional evaluation edition, so don’t worry if you need to test this out before you buy it.)
So how does it solve my problems? (The numbering of each point below matches the issues I list above)

  1. It allows you to open a VHD’s directly as well as a number of other formats, like ISO or VMWare’s formats! It's very simple to use as as well (similar interface to most compression tools like WinRAR or WinZIP), so you just go to File -> Open, select the VHD and it displays the contents of the almost VHD instantly (the 47Gb one from the previous example in about 2 seconds on my standard spec laptop). Now you browse it like you would any other file system, find the file, right click and hit Extract! There are even options to extract multiple files and keep the folder structure when extracting!  
  2. Moving between Hyper-V and VirtualPC is fine (VHD is a compatible format between them), all I have to do is uninstall the additions before I move it. I keep VirtualPC installed for this purpose but that’s all it gets used for. WinImage allows me to convert between VHD (Virtual Server, VirtualPC and Hyper-V) and VMDK (VMWare). I can also convert from an IMA (image) file to VHD and VMDK but not too it. Unfortunately there is nothing for Xen yet, but hopefully as it gets more widely used we will see something.
  3. I can rip an image of a real hard drive to a VHD or VMDK format! And because WinImage doesn’t need to be installed (it’s a single .exe which can be run from the zip archive) it makes it easy to get it onto a server! 
  4. The same is true if I have an image I can write it to a physical hard drive, so no more extracting and coping and rebuilding. Once your environment works, just deploy it!

image imageClipboard01

Automated Testing Testimonial

At the end of last week a very interesting document on doing automated testing was added to SA Architect, and what makes the document interesting is not the content (there is a lot out there on automated test) but the fact it is a document type I have never seen, it’s a testimonial.

What is a testimonial? It’s written by someone who worked with the system extensively and then provides their feedback, good and bad, on it. In some respects it’s like a white paper, but where a white paper may be more technology, brand, or system focused this is people and, to a smaller degree, project focused.

Congrats to Sacheen for providing this document and doing so well with it (it was the first time he had to write anything like this)!!
You can get the document here.
Thanks to Willy for the heads up!

Outlook 2007: POP3 and delayed email or how to avoid downloading RSS feeds too often.

I have been spoilt for a long time by living in an Exchange environment, so when I recently had to use a POP3 environment (even if it was just temporarily), I felt like I had gone back 15 years. One of the reason it feels like I have gone from Vista to Windows 3.1, is that Exchange pushes the mail down (or at least that is how I appears to work – I’m no Outlook expert), so mail arrives instantly when someone sends it.
Unfortunately POP3 is pull based and it doesn't come down until Outlook checks for mail. The horrible part is that by default it is configured for only checking every 30 minutes :( That could mean if someone misses your check window (like they would know) you could wait almost forever for their mail. Thankfully you can change that, first go to Tools -> Options
image
Next go to Mail Setup and click the Send/Receive button.
image
By default you should have one group (called All Accounts) and below that there is an option to Schedule an automatic send/receive every x minutes. In the picture below you'll see it is set to 1 minutes, which really helps (close enough to instant that it doesn't matter).
However if you are like me then you also use Outlook for RSS feeds, and that change will mean you will now be downloading feeds every 1 min! You can fix that easily by splitting RSS and Emails check times
To do that click the Edit button and remove RSS from being included, then click OK. If you are a perfectionist (which you may gather I am from my picture below), you could also click Rename to understand what it is easier. Next click the New button and do not select to include Email, just RSS. Click OK and now you should have two Send/Receive groups. You can now click on RSS in the list and set a separate interval for how often it should check (once an hour is good).  Click Close, OK and you are done :)
image

Take your toolbox with you

Previously I posted about two ways to get SysInternals to your machine, well that great bunch have released yet another method! This time in a download package which contains all the tools and none of the fluff (so no BSOD screen saver)! This is a great addition for your toolbox! You can get it from here.
Thanks to Sarah for the heads up on this!

Dev4Devs!

Earlier this year I attended a great event called Dev4Devs which is run by Microsoft on a Saturday morning at their offices and invites any developer to get up and present for 20mins! This is a great introduction into a lot of things as well as a great place to start if you want to become a presenter. Well it’s happening again in October! I will definitely be there so head over to Eben’s blog for more details.

Microsoft CRM on Linux!

I work with great people who are open minded (none of this my brand is better than your brand thinking), so much so they are IMHO the driving force behind interoperability in South Africa. When I recently presented a session on Microsoft CRM and said that it couldn’t be used on other operating systems, Henk, our Linux expert, took it as a challenge to get it to work.
The main issue is that for MSCRM to work it needs Internet Explorer and it needs IE because of the million lines of JavaScript that exist and a lot of it makes use of MSXML which is not available cross platform.
Henk did some magic and found a program/tool/package called IE4Linux! What is IE4Linux?:
IEs4Linux is the simpler way to have Microsoft Internet Explorer running on Linux (or any OS running Wine). No clicks needed. No boring setup processes. No Wine complications. Just one easy script and you'll get three IE versions to test your Sites. And it's free and open source.

They mention three versions which are 5.0, 5.5 and 6.0, however 7.0 is in beta. Since MSCRM needs 5.5 or higher it just might work! Henk did his magic to get it working and I did mine (which was very easy, just making sure my VM is running and getting the firewall configured) and without much fuss he got Microsoft CRM running on Linux!!! He has promised a whole post on IE4Linux so if you want to know more please watch his site, otherwise enjoy the pictures taken from his Linux box below of MSCRM!

crm_on_linux2-blog  crm_new_contact-blog crm_movie_on_linux-blog

Hyper-V Shrinking a VHD

Virtualisation is the way of the future, be it for demos or testing or production systems it is the future, and that means VHD files will be everywhere. However VHD files grow and grow and never shrink because of the way they are designed to work. For example if you put a 10Gb file on a VHD, it expands the VHD by 10Gb (for the disk) but if you delete a file the space of the VHD isn't reclaimed automatically.
This is pretty much ok for production systems (your VHDs live on a SAN with lots of disk or they should do for a lot of good reasons).
However if it's on your laptop for training/R&D or sending to customers being able to claim that disk space can be valuable and the advantage is it can be done manually so let me show you how it can be done in Hyper-V.
For this post I have a VHD which contains a MSSQL database (MDF and LDF) file on it, the disk space usage on the VHD for the drive looks like this:

image
So the VHD is supposedly a max of 300Gb and I have never copied that much on to it, and at the moment it contains a simple 53Gb and some change on it. The actual VHD file on my laptop looked like this, using a nice 117Gb of real disk space. So there is at least 64Gb I could get back!

image
The first step in shrinking the disk is to defrag it on the virtual machine, as the shrinking process only cleans space from the end of the disk. So if you have any data at the end like I did (see below) you'll need to (re)move it. Unfortunately as you can see I had an unfortunate "unmovable" piece of data conveniently at he end of the disk. Thankfully it turned out to be the LDF file for the SQL database.

image
So a quick truncate/empty of the LDF file (don't do that in production, but if you want to know how I did it see here) made it a lot easier to defrag the disk (especially) getting the data at the end freed up. Since I didn't have too much free time I skipped the defrag, so just working on the big (now) empty space available before the MDF (blue) file.

image
Step two is to shut down the VM, then go to the settings and go to the disk settings and click edit. This will bring up the disk edit wizard and the keep the first selected option, Compact.

image
This is very cool  because is actually loads the VHD as a disk on host operating system! In fact you can browse it and edit it (I would guess, but that may screw the compact up). This is similar to the VHDMount tool in Virtual Server. I am not sure how to do it manually in Hyper-V yet, because it would be really cool to be able to do that now.

image
After some time, let me rephrase that a significant amount of time, which in my case was a 6 odd hours,  it finished compacting the VHD file to 60Gb less!

image

Random Tool Musings

This is a little different from my regular scheduled blog posting in that it's kind of a +1 post (I promise I am not becoming one of those blogs) because there is a bunch of things I wanted to speak about but they each don't need their own post.
First off is pptFlex which is an add-on for PowerPoint which provides a DeepZoom (those at the TechEd closing know what I mean) like experience with your slide deck. It's an Office Lab add-in so a prototype that will never see the main stream. After a touch of configuration (select  backdrop, transition between slides, configuring sections) it appears to generate an XPS render of the slides with cool transitions but as XPS doesn't support animation that is the first (and biggest) loss in functionality when compared to normal PowerPoiunt. At the end of the day I doubt it will be shipped, but I think we may see these sort of transitions appearing in Office "13".
In my upcoming post on shrinking a VHD, I briefly mention that I reclaimed the disk space by emptying the SQL log file. That is a bad idea for most systems for many a reason beyond my non SQL guru mind, but if you are interested in how to do it anyway see the following article which is what I used my guidance: http://madhuottapalam.blogspot.com/2008/05/faq-how-to-truncate-and-shrink.html
Lastly there have been updates to some of my favorite tools, first from Microsoft namely StyleCop and FxCop which both are everyone. That’s very positive news especially since FxCop has been a bit stagnent but the news about another favorite tool, Reflector being taken over by RedGate (see here) does worry me. I do not think they will kill it or kill a free version but I am worried about two versions coming out (pay and free) with pay being all the features and new stuff and free being crippled or not getting enhancements. Only time will tell...