Monday 11 February 2013

jQuery ajax success callback not firing

A form that uses jQuery to call a JSON returning action to populate a dependent dropdown on the change event of another dropdown no longer worked when the script registration changed to 1.4.4. It had been working previously with jQuery 1.6.4. (This would also apply to porting apparently working code to a new ASP.NET MVC 3 with earlier jQuery version.)

Having established that the success callback was no longer being fired, I added an alert to the error callback and found that the ajax call was generating the error "jQuery#####.##### was not called" (with some random numbers). This error is thrown when the ajax call parses the data returned by the URL (action) and determines that it is malformed according to the dataType property of the settings object parameter (in this case 'json'). jQuery 1.4.x is stricter than subsequent versions when parsing JSON, and the ajax call will throw the parse error if the JSON is not properly formatted - see jQuery API.

The MVC action returning JSON data contained the following line:

return Json((from r in roles select new { Value = r.Id.ToString(), Text = r.Title }).ToArray());

It looks like when MVC returns a JsonResult containing an array, the array is deemed by jQuery 1.4.x to be not properly formatted according to the JSON specification! Version 1.6.x masks this problem, otherwise for 1.4.x changing the dataType property of the settings object parameter of the ajax call from 'json' to 'text json' allows the call to succeed.

Tuesday 22 January 2013

Report Manager URL displays blank page in IE

Having installed and configured Reporting Services on a new laptop, I found that on entering the report server URL in IE (running as administrator), IE repeatedly popped up a dialogue asking for the password (3 times), then finally displayed a blank page.

To solve this I had to do the following extra configuration steps, in addition to the usual recommendations:

  1. Ensure that the Windows account of the current logon meets the security policy configured for RS (in my case it did not have a password which was causing a problem).
  2. Add the Report Manager website to the Local Intranets zone in IE.

Friday 21 September 2012

How to integrate BIDS with TFS 2010

This is an outline of the steps that are required to integrate BIDS with TFS 2010. This link contains the detailed steps of what to do, with links to the necessary download sites:

http://arcanecode.com/2012/02/14/using-tfs2010-with-visual-studio-bids-2008-and-sql-server-management-studio/

  1. Download VS 2008 SP1 to a suitable place and install it as per step 1 in the link.
  2. Download and install VS 2008 Team Explorer as per step 2. (This is an ISO so you'll need to extract this to a suitable place and install from there.)
  3. Reinstall VS 2008 SP1. (I have not yet encountered the error described in the article at this point.)
  4. Download and install VS Team System 2008 SP1 Forward Compatibility Update for TFS 2010.
  5. Reboot.
  6. Open BIDS, go to Tools > Connect to Team Foundation Server and connect to the TFS server.

Wednesday 12 September 2012

log4net not logging to SQL Server table

By design, log4net silently fails if there are any configuration problems preventing it logging to the desired output.  To troubleshoot configuration problems, enable log4net internal debugging as described in the log4net support site FAQs.

Monday 16 April 2012

Excel 2010 unable to open file created by ExcelLibrary

This post documents a workaround for a bug in ExcelLibrary. If you create a file of size less than 7KB, Excel 2010 is unable to open the file. To solve this, prepopulate the worksheet with at least 200 rows containing empty cells.

for (int rowIndex = 0; rowIndex < 200; rowIndex++)
{
    sheet.Cells[rowIndex, 0] = new Cell(string.Empty);
}

Monday 12 December 2011

How to force view compilation in an ASP.NET MVC project

When you build an ASP.NET MVC project, the default behaviour is to exclude view files from compilation. To include views unload the project (in Solution Explorer right click the project and select Unload Project) and edit the project file (right click the project node and select Edit <project name>.csproj).  Locate the MvcBuildViews setting and change this to true.  On reloading the project, building will now compile all views.

Note that this will include all view files in the project's Views folder on disk, even if these are not added to the project.

Tuesday 4 October 2011

Using the ASP.NET membership provider in an MVC controller

You can refer to the default ASP.NET membership provider in the controller action using the Membership.Provider object, just as in ASP.NET Web Forms. This is because ASP.NET MVC uses the same ASP.NET infrastructure as Web Forms. This is how the default AccountController, built when you select the ASP.NET MVC 3 Internet Application template, provides authentication functionality. It declares an IMembershipService interface dependency, to abstract the authentication functionality, and instantiates this with the AccountMembershipService concrete class in the controller’s Initialize method:

public IMembershipService MembershipService { get; set; }
protected override void Initialize(RequestContext requestContext)
{
    if (FormsService == null) { FormsService = new
    FormsAuthenticationService(); }
    if (MembershipService == null) { MembershipService = new
    AccountMembershipService(); }

    base.Initialize(requestContext);
}


The IMembershipService interface and AccountMembershipService implementation are in the AccountModels file.

Of course you can check whether the current identity is authorized without having to directly use the Membership.Provider object, by using the AuthorizeAttribute attribute.

[Authorize]
public ActionResult About()
{
    return View();
}


Adding this attribute to the action method declaration will make the MVC runtime check whether the identity is authenticated. If the identity is not authenticated, the runtime will throw a SecurityException exception.