By exciting a series of 1s^{2} ^{1}S_{0}→1snp^{1}P_{1} transitions in heliumlike nitrogen ions with linearly polarized monochromatic soft x rays at the Elettra facility, we found a change in the angular distribution of the fluorescence sensitive to the principal quantum number n. In particular it is observed that the ratio of emission in directions parallel and perpendicular to the polarization of incident radiation increases with higher n. We find this n dependence to be a manifestation of the Hanle effect, which served as a practical tool for lifetime determinations of optical transitions since its discovery in 1924. In contrast to traditional Hanle effect experiments, in which one varies the magnetic field and considers a particular excited state, we demonstrate a "soft x-ray Hanle effect" which arises in a static magnetic field but for a series of excited states. By comparing experimental data with theoretical predictions, we were able to determine lifetimes ranging from hundreds of femtoseconds to tens of picoseconds of the 1snp^{1}P_{1} levels, which find excellent agreement with atomic-structure calculations. We argue that dedicated soft x-ray measurements could yield lifetime data that are beyond current experimental reach and cannot yet be predicted with sufficient accuracy.