Fancybox with Jquery and partial views

Recently I’ve been working on a site redesign and I thought a nice little feature would be to have a fancybox (read lightbox) and inside there provide some basic site statistics, current user count etc.

So the aim is to have a fancybox appear with it’s content loaded via ajax from a partial view on the server. The content will appear when a button is clicked on the page.

I’ll be using the following :

Partial View

[HttpPost]
public PartialViewResult p_popup()
{
   return PartialView();
}

Javascript

$(document).ready(function() {
   $("#menuButton").click(function() {
      e.preventDefault();
      $("#overallApplicationNavigation").overallNavigation.close();
      // Close the overall model
      // Open a fancybox
      $.ajax({
         url: '/fb/p_popup',
         type: 'POST',
         data: '',
         success: function (data) {
            $.fancybox(data);
         }
    });
   });
});

And that’s it, I prefer this method to using templates on the client side. In a follow up to this I’ll deal with posting back from forms with validation.

Advertisements

WIF and load balancing with MVC 3.

Recently I’ve been getting to grips with WIF and the starter STS which I must say is an excellent starting point. A requirement for a project that I’ve been working on was to enable the site to run in a load balanced environment without any affinity to a particular node.

From the outset this seemed quite straight forward. After customizing the STS to use our own credential store and aligning the machine keys things looked to be rocking, well from an STS point of view.

After adding the STS reference and deploying the web application everything looked OK initially, looking in firebug I could see plenty of requests reporting “500” internal server error.

After much investigation it became clear that one of the nodes couldn’t access the token due to it being protected via DPAPI.

The following assumes that you have a serverCertificate inside the microsoft.identitymodel node in your config. It also assumes that you application pool has access to find the certificate in the local store.

Changes to the global.asax file.

New event handler

void onServiceConfigurationCreated(object sender, ServiceConfigurationCreatedEventArgs e)
{
List<CookieTransform> sessionTransforms = new List<CookieTransform>(new CookieTransform[]
{
new DeflateCookieTransform(),
new RsaEncryptionCookieTransform(e.ServiceConfiguration.ServiceCertificate),
new RsaSignatureCookieTransform(e.ServiceConfiguration.ServiceCertificate)
});

SessionSecurityTokenHandler sessionHandler = new SessionSecurityTokenHandler(sessionTransforms.AsReadOnly());
e.ServiceConfiguration.SecurityTokenHandlers.AddOrReplace(sessionHandler);
}

Changes to application start method.

protected void Application_Start()
{
FederatedAuthentication.ServiceConfigurationCreated += onServiceConfigurationCreated;
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}

The preceding enabled tokens to be treated the same on all nodes in the cluster.

MVC 3 and Solutions folders

I came across and interesting issue today with the MVC 3 tooling. For organisation in an overall solution I wanted to create a solution folder for a new web application that I was creating. Upon trying to create the new application an error was triggered in the tooling.

The solution is then only partially created and various references are missing from the application. To work around this just create the application at the root level of the solution and then move it into the solution folder.