13

Is it possible to configure a location in Web.config to allow only local connect...

 2 years ago
source link: https://www.codesd.com/item/is-it-possible-to-configure-a-location-in-web-config-to-allow-only-local-connections.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Is it possible to configure a location in Web.config to allow only local connections

advertisements

I've got a page in an ASP.Net app (its Mvc actually but not important) and I would like to only allow connections to this page from the local machine. I would love to do something like this in Web.config:

<location path="resources"><system.web><authorization><allow ips="local"/></authorization></system.web></location>

I know this is possible with a simple check in the page code behind (or controller) and its even possible just with IIS configuration but I would love a Web.config config as this would be the most elegant solution in my opinion. Anyone know if this is possible?

Thanks

Guido


You can ask IIS to restrict access to a resource by IP address from within the Web.config:

<location path="resources">
  <system.webServer>
    <security>
      <ipSecurity allowUnlisted="false">
        <clear/>
        <add ipAddress="127.0.0.1"/>
      </ipSecurity>
    </security>
  </system.webServer>
</location>

More info

EDIT: As Mike pointed it out in the comment below, this requires the IP and Domain Restrictions module to be installed. Thanks Mike!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK