Conditionally print subsection in Beamer

I've ported from PowerPoint my university's template in Beamer, and added some code to display sections (and subsections when they exists) in the header.

This is the code snippet I've put in the headline template for this purpose:

\begin{beamercolorbox}[wd=0.6\paperwidth,ht=0.1\beamer@PoliMI@headheight]{section in head/foot}%
\ifx\insertsubsection\empty\else%
\fi%
\strut\par%
\end{beamercolorbox}\\%


However, when "exiting" from subsection (issuing \subsection*{}), the dash after the section name is still printed.

How can I test if the subsection name is void?
As an alternative, how can I make \insertsubsection empty?

MWE:

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}\normalfont
\usepackage[T1]{fontenc}

\fi\strut\par%
\end{beamercolorbox}%
}

\begin{document}
\section{aaa}
\begin{frame}~\end{frame}
\subsection{bbb}
\begin{frame}~\end{frame}
\subsection*{}
\begin{frame}~\end{frame}
\end{document}


In the third frame, only "aaa" must show up, and not "aaa -".

UPDATE: If subsection is not yet defined, \insertsubsection is empty, whereas if a \subsection*{} is issued, the macro is expanded in \expandafter \hyperlink \subsectionlink, either the subsection is empty (\insertsubsectionhead expands to \hyperlink {Navigation\the \c@page }{}) or not (\insertsubsectionhead expands to \hyperlink {Navigation\the \c@page }{bbb} in the second frame).

• Welcome to TeX.SE. Thanks for posting the problem code snippets. However you should also post a fully compilable MWE that reproduces the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. It is still going to be useful in testing that a proposed solution actually worked. Oct 1, 2014 at 8:33
• @PeterGrill: please see edited question. Oct 1, 2014 at 9:05

I have replaced the code snippet with

\ifx\insertsubsection\empty\else%
\ifdefempty{\subsecname}{\relax}{%
}%
\fi


and IT WORKS!!!
Unfortunately needs the etoolbox package to be loaded...

EDIT:

\setbox0=\hbox{\subsecname\unskip}\ifdim\wd0=0pt\else%
\fi%


also works and does not require etoolbox.
I don't know if this is the "cleaner" solution.

I can't comment but I had issues with the 2nd solution of @Astrinus and wanted to share it nonetheless.

\subsecname is not deleted by default when a new section is created. Replacing it with \insertsubsectionhead worked to solve it for me.

\setbox0=\hbox{\insertsubsectionhead\unskip}\ifdim\wd0=0pt\else%
\fi%


I had issues with recognizing end of subsection by:

\ifx\insertsubsection\empty


Limiting the SubSection in braces made it working:

{
\subsection{SubSection Title}
<subsection frames>
}
<other frames>


The condition correctly differed between frames inside and outside that SubSection