Digital Tool Factory blog - Page 6 of 34 - Backend web development in Atlanta GA Digital Tool Factory blog - Page 6 of 34 - Backend web development in Atlanta GA

The Digital Tool Factory Blog

How to fix problems with small fonts when using the rotativa nuget package

Does the actual html look fine but the text on the printed pdf look way, way too small when you actually print the thing?

  1. In the MVC Controller – add in

    CustomSwitches = “–disable-smart-shrinking”,

  2. Check for long strings of unbroken text, in my case it was a fake underline of underscores (______) which was causing problems.

Blogged about largely in case I ever need to remember it later.


07
Jul 14


Written By Steve French

 

ASP.net MVC remote validation does not check for empty strings

This is a lesson I learn too frequently – asp.net mvc remote validation does not validate when the textbox (or whatever) is empty – it will not check empty strings and the event simply won’t fire.  Why it does this I don’t know but it does not.  I spent an annoying amount of time relearning that recently.  I guess Microsoft wants you to use the required validation fields first, but I run into many situations where the object is not required per se, but is required if some other data is entered.

 

What is the solution?  I’ve had great luck using MVC FoolProof Validation – available here.


14
May 14


Written By Steve French

 

Linq projection with the extension method syntax

I’ve looked this up an embarrassing number of times – here is how you do linq projection with the extension method syntax

List<TypeClassification> typeClassifications = ctx.Classes.Select(e => new TypeClassification() {Name = e.Name, TypeClassificationID = e.ClassificationID}).ToList();

Hopefully I shall remember.  I’m not sure why I can’t remember the exact syntax.


18
Apr 14


Written By Steve French

 

A non definitive list of 64 html escape characters for currency

'Currencies on White Background' photo (c) 2011, Images Money - license: http://creativecommons.org/licenses/by/2.0/I recently had to integrate html escape characters for currency symbols on a project, and much to my surprise I could not find any good definitive list html escape characters for currency codes. These are also known as escape characters, character entities or extended characters.  I had to find them all more or less one by one.  Here is what I came up with. For some reason WordPress is not letting me post the escape characters as escape characters, so I have attached a simple text file containing a list of 64 html escape characters for currency symbols. Hopefully this will save someone else 45 minutes.

Here is what is in the file – it is in the Name – Abbreviation – Symbol format.

Australian Dollar – AUD – ₳
Barbados Dollar – BBD – $
Bulgarian Lev – BGN – л в
Bermudian Dollar – BMD – $
Brazilian Real – BRL – R$
Belize Dollar – BZD – $
Canadian Dollar – CAD – $
Swiss Franc – CHF – ₣
Chilean Peso – CLP – ₱
Chinese Yuan Renminbi – CNY – ₩
Colombian Peso – COP – ₱
Costa Rican Colon – CRC – ₡
Czech Koruna – CZK – Kč
Danish Krone – DKK – kr
Dominican Peso – DOP – ₱
Egyptian Pound – EGP – £
Euro Dollar – EUR – €
Fiji Dollar – FJD – $
British Pound – GBP – £
Guatemalan Quetzal – GTQ – Q
Hong Kong Dollar – HKD – $
Honduran Lempira – HNL – L
Croatian Kuna – HRK – kn
Hungarian Forint – HUF – Ft
Indonesian Rupiah – IDR – Rp
Israeli New Shekel – ILS – ₪
Indian Rupee – INR – ₨
Iraqi Dinar – IQD – Ű
Iceland Krona – ISK – kr
Jamaican Dollar – JMD – $
Jordanian Dinar – JOD – Дин.
Japanese Yen – JPY – ¥
Kenyan Schilling – KES – KSh
Korean Won – KRW – ₩
Kuwaiti Dinar – KWD – Дин.
Cayman Islands Dollar – KYD – $
Lithuanian Litas – LTL – Lt
Latvian Lats – LVL – Ls
Moroccan Dirham – MAD – MAD
Mexican New Peso – MXN – ₱
Malaysian Ringgit – MYR – R&:#77;
Norwegian Kroner – NOK – kr
New Zealand Dollar – NZD – $
Omani Rial – OMR – ﷼
Peruvian Nuevo Sol – PEN – S/.
Philippine Peso – PHP – ₱
Pakistan Rupee – PKR – ₹
Poland Zloty – PLN – zł
Qatari Rial – QAR – ﷼
Romania New Leu – RON – lei
Russian Rouble – RUB – р&#1091б
Saudi Riyal – SAR – ﷼
Swedish Krona – SEK – kr
Singapore Dollar – SGD – $
Thai Baht – THB – ฿
Turkey Lira – TRY – ₤
Trinidad and Tobago Dollar – TTD – $
Taiwan Dollar – TWD – $
US Dollar – USD – $
Vietnamese Dong – VND – ₫
East Caribbean Dollar – XCD – $
South African Rand – ZAR – R
Bahamas Dollar – BSD – $
Bahrain Dollar – BHD – $


17
Oct 13


Written By Steve French

 

Five things should should know about the new asp.net identity membership system

I’m trying my first asp.net mvc 5 project, which more or less forces you to use the new asp.net identity framework for membership. It’s in the using Microsoft.AspNet.Identity namespace.

While a vast improvement over the original asp.net membership – I do not see any massive benefit over the MVC 4 Simple Membership system.  Here are 5 things you need to know about the asp.net identity system before you upgrade

  1. The ID column is stored as a guid, and not an int – One of my favorite things about the simple membership system was being able to use int columns for ID – no more of that
  2. In the default project, all of the membership tables will be stored in Local DB, even if you change the connection string in the web.config
  3. MVC introduces a peculiar (to me at least) way of creating the Database tables for membership in the LocalDB – in the IdentityModel.cs file in the Models folder, you will see the following bit of code

    public class ApplicationDbContext : IdentityDbContextWithCustomUser
    {
    }

    this will create the following tables in the Local DB

    • ASPNetUsers
    • ASPNeRoles
    • ASPNeTokens
    • ASPNetUserClaims
    • ASPNetUserLogins
    • ASPNetUserManagements
    • ASPNetUserRoles
    • ASPNetUserSecrets

    if you are running a separate database you will find it quite confusing to get the membership and the other data in the same context (the error message are rather opaque.  To fix the matter, add in the following code in your regular data context class and comment out the ApplicationDbContext : IdentityDbContextWithCustomUser in IdentityModel.cs

    public DbSet ApplicationUsers { get; set; }
    public DbSet Roles { get; set; }
    public DbSet Tokens { get; set; }
    public DbSet UserClaims { get; set; }
    public DbSet UserLogins { get; set; }
    public DbSet UserManagements { get; set; }
    public DbSet UserRoles { get; set; }
    public DbSet UserSecrets { get; set; }

    and everything will both be in the same database and the same data context.

  4. The quick and easy way of getting the User ID (comparable to WebSecurity.CurrentUserID is User.Identity.GetUserID() – that will return the guid of the user.
  5. It is pleasantly integrated with entity framework code first, and will probably be a positive feature over time.

05
Oct 13


Written By Steve French

 

How to fix 502 Errors in WordPress on Windows Azure Websites

For the past month I’ve been getting the following error

502 – Web server received an invalid response while acting as a gateway or proxy server.There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server.

I searched the internet – all to no avail – I tried Stack Overflow – no luck.

However, when I tried on the Azure Forums, they suggested turning on Failed Request tracing – which I did.

And while the error logs did not reveal any helpful error information, like “Setting A is set to true when it should be set to false for this to work” it did list quite a few entries for Glimpse – which I was using for my main website (the blog is in a subdirectory).  On a hunch I turned that off, and presto!  The site is working like a charm.  Why Glimpse when the site is deployed I have no idea, but I’m thrilled to not have the error anymore.


16
Sep 13


Written By Steve French

 

How to set mime types, aka Content Types with Windows Azure Storage

The Problem

I recently came across the conundrum of files not being availble for download after I uploaded them to Windows Azure Storage.

The Cause

Usually the problem is an incorrect mime type, but since Azure does not have mime types I had to do some more digging.

The Solution

It turns out there is a property called “ContentType” that must be set on the Azure Storage Blob programatically – here is an example

CloudBlockBlob blockBlob = container.GetBlockBlobReference(filename);

if (GetFileExtension(filename).ToUpper() == “.SWF”)
{
blockBlob.Properties.ContentType = “application/x-shockwave-flash”;
}
else if (GetFileExtension(filename).ToUpper() == “.MP4”)
{
blockBlob.Properties.ContentType = “video/mp4”;
}
blockBlob.SetProperties();

Once I did that everything worked as intended.


01
Aug 13


Written By Steve French

 

How to fix problems in adding ssl certs on Windows Azure Websites

For some reason, most likely because you never do it more than once a year, adding ssl certificates to a server is poorly documented and unnecessarily complicated.  Here are some things I learned recently about adding ssl certs on Windows Azure Websites.

I recently added a cert to this site, https://digitaltoolfactory.net which is hosted on Windows Azure Websites.  It looks simple enough, just upload a file, sure it’s a .pfx file, but those are avilable aren’t they?

Off I go to NameCheap.com, plunk down my $10 and get a GeoTrust Rapid SSL Certificate.  Then you have to generate a CSR – from there just go to your IIS manager and

  1. Click on “Create Certificate Request” (Common Name is the domain name btw)
  2. Do Everything it asks
  3. You will then plug that into your SSL Provider, they will then email (of all things) you back a long code
  4. Go Back to your IIS Manager and click on “Complete Certificate Request”
  5. You will then have a file – this is not the file you use
  6. From there click on the server certificate, and then click “Export”
  7. That will generate the .pfx file
  8. From there you can upload the file to Azure
  9. You then have assign the bindings to that certificate
  10. Restart the site in the Azure Manager

That’s it!

There are a few caveats.

The big one is that if you have any errors in this process Azure will not tell you – instead all you will get is the big scary “This site claims to be DigitalToolFactory.net, but the actual certificate is for *.WindowsAzureWebsites.net”.

The other caveat is that Microsoft is charging $9.00 per month to host a site site with Secure Socket Layer bindings, which is ridiculous.   By my estimation it costs more to host the cert than to host the actual site, which makes it unique in all web hosting.  Why they do this I don’t know.  I’m glad to have the option, but the amount seems ridiculous – hopefully that fee will drop soon.


26
Jul 13


Written By Steve French

 

How to track outbound links in the new version of Google Analytics

So the Gods of Google have gone and changed their basic Google Analytics code to something that works slightly better, and now your outbound link tracking code doesn’t work.

Here is how you fix that – first make sure you have the most recent (as of July 2013 Google Analytics code, it looks something like this)

<script>
(function (i, s, o, g, r, a, m) {
i[‘GoogleAnalyticsObject’] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, ‘script’, ‘//www.google-analytics.com/analytics.js’, ‘ga’);

ga(‘create’, ‘UA-XXXXXXXX-1’, ‘mydomain.com’);
ga(‘send’, ‘pageview’);

var clientId = ”;
ga(function (tracker) {
clientId = tracker.get(‘clientId’);
});
</script>

 

If it does not look more or less like that, then do not use the code below.

Now make the links you want to track look  like this

<a href=”http://www.SomeOtherDomain.com” onClick=”ga(‘send’, ‘event’, ‘Outbound Links’, ‘click’, ‘http://www.SomeOtherDomain.com’)” target=”_blank”>www.SomeOtherDomain.com</a>

Note the onclick event – that is the key thing.

 

Where can you see the result?  They do not show up as page views  (like they used to) instead they are treated as “Events”.  To see them, go to (in the main Google Analytics screen)

1.  Standard View

2. Content

3.Events

4. OverView

5. Event Label

And there you are.  Not exactly intuitive, but not bad.

 


08
Jul 13


Written By Steve French

 

When the jquery $.post doesn’t work the way you expect it to…

The Problem

In my was posting a contact form to an outside service, and then redirecting to a page on the same site.  I thought, Aha, I will use the handy jquery .post command – it looked something like this.

$.post(“https://www.outsidesite.com/FormSubmit.php”, $(“#myform”).serialize());
window.location.href=’http://www.MySite.com/SomePage/’;

But curiously, half of the time I filled out the form the data did not reach the outside server, and the other half the redirect did not happen.

The Cause

$.post is an asynchronous operation by definition – and cannot be made synchronous.

The Solution

Just use the regular jquery .ajax function, and set async to false

$.ajax({type: ‘POST’, url: “https://www.outsidesite.com/FormSubmit.php”, data: $(“#myform”).serialize(),async:false});
window.location.href=’http://www.MySite.com/SomePage/’;

That’s it, now the browser waits until the submission is complete and everything works as expected.

 


27
Jun 13


Written By Steve French

 




Copyright 2011 Digital Tool Factory. All Rights Reserved. Powered by raw technical talent. And in this case, WordPress.