0

I am doing a web service in .NET containing a server file (.asmx) and a client interface (.aspx). The visitors should be able to visit only the client aspx site ( urlXXX:portYY/Client.aspx) However, when I remove the "/Client.aspx" part from the URL, I get into the project directory and this should not be possible. (So far, I am running the project just on localhost.)

Is there any way, how restrict getting into other parts of the solution? The only possibility I could think of is creating a separate project for the client aspx site, however, even then the visitor is able to get into the directory containing that site.

Storm
  • 3,062
  • 4
  • 23
  • 54

2 Answers2

1

You should be able to control explicit access using your web.config. Have a look at this example (exclaimer: I've copied this straight from this MS page):

<configuration>
    <system.web>
        <authentication mode="Forms" >
            <forms loginUrl="login.aspx" name=".ASPNETAUTH" protection="None" path="/" timeout="20" >
            </forms>
        </authentication>
<!-- This section denies access to all files in this application except for those that you have not explicitly specified by using another setting. -->
        <authorization>
            <deny users="?" /> 
        </authorization>
    </system.web>
<!-- This section gives the unauthenticated user access to the Default1.aspx page only. It is located in the same folder as this configuration file. -->
        <location path="default1.aspx">
        <system.web>
        <authorization>
            <allow users ="*" />
        </authorization>
        </system.web>
        </location>
<!-- This section gives the unauthenticated user access to all of the files that are stored in the Subdir1 folder.  -->
        <location path="subdir1">
        <system.web>
        <authorization>
            <allow users ="*" />
        </authorization>
        </system.web>
        </location>
</configuration>

EDIT: Take a look at this question for more info on denying access to explicit folders as well.

Community
  • 1
  • 1
Nick
  • 2,285
  • 2
  • 14
  • 26
  • I have tried it, but somehow, I am still able to get into almost all directories, and even some text and xml files, stored inside them. – Storm Jul 11 '13 at 08:44
  • Added a link to another question which points out how to deny access to folders. The practice would usually be to blanket deny access to the folder, then explicitly add files you want to make available. – Nick Jul 11 '13 at 08:49
0

So, basically I have managed to find a workaround, by adding the following code into the Web.config:

<system.webServer>
    <defaultDocument>
        <files>
            <add value="Client.aspx" />
        </files>
     </defaultDocument>
</system.webServer>

...which makes the Client a default web-page, thus preventing to see the directory. However, I will leave this topic open in case someone comes with a more elaborate and sophisticated solution.

Storm
  • 3,062
  • 4
  • 23
  • 54