A modified Monte Carlo method in conjunction with the canonical and grand canonical ensembles is proposed for simulating adsorption in spatially inhomogeneous porous systems. Unlike the traditional Monte Carlo simulation in terms of the grand canonical ensemble, the simulation for the regions of pore space having no direct communication with the bulk phase is performed in local conditions of the canonical ensemble.