I have done it several time with no problem, a polite request to the FA is habitually all you need. The trans-Atlantic or trans-Pacific flights can be quite boring for the cockpit crew so they sometimes enjoy a nice chat. If you know about the industry and airplane you can stay there for a while (30-45 min).
Had a real good experience in January on a LH A-340 between FRA and IAD. I was seated in J, asked for the visit (was granted 30min late) and spend 45 min in the cockpit over Northern Quebec. At the end I asked for the jump seat and my request was accepted.
So 20min before landing the chief FA came to be and I returned in the cockpit with another FA who was landing there for the first time. It was a great experience.