Monday 14 March 2011

Thursday 10 March 2011

Re-applying jQuery functions in replaced/inserted content

I had an issue where a jQuery function was not working in replaced content (this was being replaced on a timer every 5 seconds).
The content had an link which had a rel attribute, we used this as a mechanism to apply the boxy function to links in the server code, and then we had a javascript file that applied the boxy function to all a tags that had a rel attribute of boxy to all the documents.

When this was running, the boxy popup didn’t work on the page (in the replaced content).

What you have to do is re-apply the jQuery again (see code). When this was done, the boxy pop up worked again. Note: after this, I've read about the live() function [http://api.jquery.com/live/] but not too sure how this works with plugin functions - haven't had the time to experiment with it yet.

 $(function () {  
   $('#div_id').updateStatus();  
 });  
 $.fn.updateStatus = function () {  
   return this.each(function () {  
     window.setInterval  
     (  
       refreshStatus,  
       5000  
     );  
     function refreshStatus() {  
       var param1 = $('#statusId').val();  
       var param2 = $('#reportsId).val();  
       $.get  
       (  
         AJAXUrls.getStatusURL, { Param1: param1 },  
         function (data) {  
           $('#status').empty().append(data);  
         }  
       );  
       $.get  
       (  
         AJAXUrls.getStatusReportURL, { Param1: param1, Param2: param2 },  
         function (data) {  
           $('#reports').empty().append(data);  
           $('a[rel=boxy]').boxy(); // Boxy re-applied.  
         }  
       );  
     };  
   });  
 }  

Friday 28 January 2011

Running mixed mode assemblies

If your running .net 4.0 and you have a dependency on a lower version assembly (in my case 2.X) you might get this error

FileLoadException was unhandled
Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

This can be fixed obviously by building the dependency to 4.0 or with this config (if you don't have control of the assembly as in my case)

<
startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<startup/>

key config is useLegacyV2RuntimeActivationPolicy="true"

(under <configuration> )

.NET Framework 4 Client Profile

I had a problem where I was referencing Microsoft.IdentityModel, and using this as a using statement such as

using Microsoft.IdentityModel.Protocols.WSTrust;

but got the complier error 'the type or namespace name ... could not be found'. This was completely driving me nuts - lost 0.5 days on this. When I include the reference initially, intellisense would pick it up, but on compiling it failed with that error, then intellisense stopped picking it up.

It turns out that I was using '.NET Framework 4 Client Profile' as the target framework, on changing to '.NET Framework 4', it fixed the problem.

Thursday 27 January 2011

XML from WIF SecurityToken

If you ever need to see the XML in a SecurityToken (in my case a SamlSecurityToken) then you have to write it out using a XmlWriter:

            var sth = new Microsoft.IdentityModel.Tokens.Saml11.Saml11SecurityTokenHandler();
            var ms = new MemoryStream();
            var writer = XmlWriter.Create(ms);
            sth.WriteToken(writer, token);
            writer.Flush();
            ms.Seek(0, SeekOrigin.Begin);
            var xml = new StreamReader(ms).ReadLine();


where token is a SecurityToken object (System.IdentityModel.Tokens).

WCF Logging

WCF Logging - put this code block in under <configuration>

<system.diagnostics>
    <sources>
      <source propagateActivity="true" logKnownPii="true" name="System.ServiceModel"
       switchValue="Warning">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="traceListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
      <source name="Microsoft.IdentityModel" switchValue="Warning, ActivityTracing">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="traceListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="c:\logs\log.svclog" type="System.Diagnostics.XmlWriterTraceListener"
       name="traceListener" traceOutputOptions="None">
        <filter type="" />
      </add>
    </sharedListeners>
    <trace autoflush="true" />
  </system.diagnostics>

Introduction

Hello,

this is my blog mainly for keeping notes to myself - if anyone else finds it useful than great.