The magnetic field of a long solenoid is ## B_z=n \mu_o I ## throughout its entire length and is very uniform with ## B_r=B_{\phi}=0 ##. ## \\ ## It is a very well-known (or somewhat well-known) problem from advanced E&M theory that the magnetic field ## B_z ## at the openings of the solenoid is ## B_z=\frac{1}{2}n \mu_o I ##. ## \\ ## For the details: This result is because the magnetic field of a magnetized cylinder (with the same dimensions as the solenoid) with uniform magnetization ## M_z ## in the z-direction has the exact same magnetic field pattern as the solenoid, (both inside and outside the cylinder), with ## B_z= M_z ## inside and anywhere near the middle region. Some very straightforward calculations using the magnetic pole method give the result that there are surface magnetic charge densities ## \sigma_m=\vec{M} \cdot \hat{n} ## at the endfaces, resulting in a contribution of ## B_z=-(1/2) M_z ## inside the cylinder near this "plane of surface charge", (comes from ## H_z=-\frac{\sigma}{2 \mu_o} ## inside the cylinder, near the endface, with an inverse square law fall-off as one moves away from the endface), and ## \vec{B}=\mu_o \vec{H}+\vec{M} ##. (Note: This result is quite basic for understanding the concept of magnetic surface concepts in the magnetic surface current methodology for computing the magnetic field of a permanent magnet. Notice how the magnetic surface current per unit length ## \vec{K}_m=\vec{M} \times \hat{n}/\mu_o ## corresponds to the solenoid current per unit length of ## nI ##).## \\ ## In any case, this is a well-known result that is presented in advanced E&M courses, and so the result can be used without going through all of the details. And your second line of reasoning in the OP is the correct one.