One of the great ASP.NET web apps I’ve started using is BlogEngine.NET, a fairly simple yet powerful CMS. While it handles basic CMS type functionality without problems, there are something which it doesn’t make particularly easy, such as displaying navigation trees.
This can be largely overcome by extending some of the controls which BlogEngine ships with, such as the post list. I changed this to display a list of sub pages for the current page. Once you set a page’s parent page, the subnav is rendered on the masterpage.
Read more »
Since I started using the DevExpress Scheduler a few weeks back I’ve found a few limitations in the 2011 version. The killer for me was the lack of appointment IDs for recurring appointments.
Read more »
Forms which need a user’s address, or even just their country can be tedious to fill out, especially if you need to collect latitude and longitude. Yahoo’s Geolocation API can simplify the process by looking up latitude, longitude and country from a postal/zip code. The function below takes five arguments and uses jQuery to add a click handler. When the button is clicked, an AJAX request is sent to the Yahoo geolocation API via jQuery, the the resulting XML is parsed and the form fields are populated.
This has the benefit of needing just one piece of data (postcode) instead of four. The one problem with this is that the same origin policy prevent making AJAX calls to a separate domain. Unfortunately, this means you need an intermediate web service hosted on the same domain as the page which passes on the request. This just needs to return a URL via cURL (PHP) or WebClient (ASP.NET).
Then in JavaScript, the result can be parsed from the returned XML (unfortunately, Yahoo’s API doesn’t currently support JSON).
Read more »
I’m a big fan of jQuery, but so far I’ve only used it for effects. I recently did a draggable, resizable football shirt customization widget for an ASP.NET site and ran into some problems on the way. It’s not quite as simple as just calling $(‘#ele’).draggable().resizable(); due to a jQuery bug, so a bit of hackery is needed.
First, the controls to display the image which the user uploads.
Read more »
I’ve been working with Kentico recently and I needed a section of text on the MasterPage ediatble by the admin, of which there was only one instance. The problem is, if you use a <cms:CMSEditableRegion>, you end up with one instance on every page as the property is stored on the page. In Umbraco you’d probably use a either page in the CMS specifically to hold the text or a new property on the root node.
Read more »
The .NET documentation seems fairly sparese with examples for working PayPal API calls, so here’s my contribution. The CancelSubscription method may not be 100% working, but I believe the problem is with my Paypal account. You also need paypal_base.dll from the SDK. The methods are:
- SetExpressCheckout – Sets the token and returns a URL to which to redirect the user.
- GetExpressCheckoutDetails – Checks whether a token is valid on returning from PayPal
- DoExpressCheckout – Initiates a payment
- CreateRecurringPaymentsProfileCode – Creates a subscription with an optional initial amount
- CancelSubscription – Cancels a subscription
Read more »
Blog4Umbraco is probably one of the only ways to get a decent blog for Umbraco. I had a site which used some other JavaScript and lots of jQuery UI which I neeed to integrate, but as soon as I applied my MasterPage, the AJAX comment form broke. A quick search shows a few people have had this problem, so I want to post my fix. It’s almost embarrassingly simple
Read more »
I’ve been using Umbraco recently, and always find it hard to find XSL templates or spend hours tweaking one when countless other people must have done the same thing, but not published the finished stylesheet.
Below is a navigation breadcrumb template which prints a trail to the current page, starting with level 1.
Read more »
ASP.NET and medium trust typically don’t get along well once you start using third party libraries. It really should, however, be easier to get the Entity Framework working on medium trust, and this had me baffled for a few hours trying to split the EDMX file and other fruitless solutions.
To get this working I needed to:
- Move the EDMX to a separate assembly.
- Set the EDMX metadata artifact processing to ‘Embed in output assembly’.
- Add a reference in the site.
- Change the connection string to
<add name="ShopEntities" connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider connection string="Data Source=servername;Initial Catalog=dbname;User Id=username;Password=P@55word;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
Which every guide claimed would work. There’s one more step if you have custom partial entity classes (in App_Code). If so, these also need to be moved to your output assembly, as you can’t split partial classes across assemblies. Lastly, change the namespace in your partial classes to the same as your output assembly, and everything should work.
The Cache object in ASP.NET isn’t like other collections, probably because it needs to be specialized so it doesn’t make use of generics. Unfortunately, that makes it more difficult to work with. This small utility method removes an object from the cache by key using a predictate. You could easily modify it to compare either of the IDictionaryEnumerator’s Key or Value properties.
/// <summary>
/// Removes an item from the cache using a Predictate to match the key.
/// </summary>
/// <param name="keyCriteria">The Predictate to use for each key to determine whether the entry should be removed.</param>
/// <summary>
/// Removes an item from the cache using a Predictate to match the key.
/// </summary>
/// <param name="keyCriteria">The Predictate to use for each key to determine whether the entry should be removed.</param>
public static void RemoveFromCache(Predicate<string> keyCriteria) {
IDictionaryEnumerator enuma = HttpContext.Current.Cache.GetEnumerator();
while(enuma.MoveNext()) {
if(keyCriteria(enuma.Key.ToString())) {
HttpContext.Current.Cache.Remove(enuma.Key.ToString());
}
}
}