ShawnMolloy
MIS
I have a cookie class that calls this decode method. Occasionaly its throwing a weird exception. In the case of this excpetion being thrown I'd like it to remove the cookie and perform some other actions, instead of halting the application and displaying this exception to the user.
what are my options?
Shawn Molloy
Seattle, WA
what are my options?
Code:
/// <summary>
/// Decodes a string
/// </summary>
/// <param name="text">String to decode</param>
/// <param name="cookieProtection">The method in which the string is protected</param>
/// <returns>The decoded string or throws InvalidCypherTextException if tampered with</returns>
public static string Decode(string text, CookieProtection cookieProtection) {
if (string.IsNullOrEmpty(text)) {
return text;
}
byte[] buf;
try {
buf = CookieProtectionHelperWrapper.Decode(cookieProtection, text);
}
catch(Exception ex) {
throw new InvalidCypherTextException("Unable to decode the text", ex.InnerException);
}
if (buf == null || buf.Length == 0) {
throw new InvalidCypherTextException("Unable to decode the text");
}
return Encoding.UTF8.GetString(buf, 0, buf.Length);
}
}
Shawn Molloy
Seattle, WA