June 2017 - Digital Tool Factory blog June 2017 - Digital Tool Factory blog

The Digital Tool Factory Blog

Something to watch for on WordPress shortcodes

The first inclination is to create a shortcode that will look like [MyShortCode]My Only Parameter[/MyShortCode], which would look like this

function MyShortCode_func($content = null){
//————-stuff happens
return $processedContent;
}

However, if you want to have parameters = you must have the $atts parameter in the function, even if it is not used.  The proper function would be

function MyShortCode_func($atts, $content = null){
//————-stuff happens
return $processedContent;
}


12
Jun 17


Written By Steve French

 

How to fix problems with password reset tokens

For some reason, asp.net identity 2 generates password reset tokens that are not property url encoded, but does send them as part of a querystring.  Therefore – when you send out the email – the web browser will add spaces to the code, which renders it invalid.  The way around that is to base 64 encode (and decode) the code as it is sent and interpreted.  Below are the Base64 extension methods.

Also – make sure there is a guid (any guid) in the SecurityStamp column in the AspNetUsers table – that will also cause it to claim that the code is invalid.

public static string ConvertToBase64(this string str)
{
byte[] encbuff = Encoding.UTF8.GetBytes(str);
return HttpServerUtility.UrlTokenEncode(encbuff);
}

public static string ConvertFromBase64(this string str)
{
byte[] decbuff = HttpServerUtility.UrlTokenDecode(str);
return Encoding.UTF8.GetString(decbuff);
}


10
Jun 17


Written By Steve French

 

How to fix problems with file creation and web deployment in asp.net

The scenario – you have an asp.net app that creates a file of some kind – everything works great – then you upload it and the file is not created.

It turns out that Visual Studio will not deploy an empty folder, or a folder that it seems as empty anyway – if the app is creating the files, the new files will not be visible to Visual Studio.  Visual Studio will see an empty folder and not create it on the server.  You will run the app, and it will try to save a file to a folder that isn’t there, and will create an error.

The easiest way to do that is to just create a blank text file in the folder.  Visual Studio will see that file, and then upload the text file (in doing so creating the folder) and the app will have a folder to create the new file in.


05
Jun 17


Written By Steve French

 




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