Just ask either when you board the aircraft or during the flight whether you could visit the flightdeck. Easy as that.
Some reasons why you may be denied access:
-Pilot training
-Pilots eating dinner/lunch
Tri
------------------
"Ayline 221 airbourne"