If the requirement for storing the url to id mappings in an external text file is not critical, then you can use Rewrite Maps to accomplish this functionality (the xml is not formatted correctly):
<rewriteMap name="detalle" defaultValue="no-exist">
<add key="optiona" value="1" />
<add key="optionb" value="2">
...
</rewriteMap>
<rule name="rule">
<match url="^([^?/]+)\.html$" />
<conditions>
<add input="{detalle:{R:1}}" pattern="^no-exist" negate="true" />
</conditions>
<action type="rewrite" url="guias_detalle.asp?cod={detalle:{R:1}}" />
</rule>