how to stop web site directory outside file access from web in iis7
I have a windows server 2008. i'm adding few web site using IIS7 . But all web can access outside file. for example:
@{ DirectoryInfo di=new DirectoryInfo("c:\\");}
@foreach (var item in di.GetFiles())
{
<div>@item.FullName</div>
}
This code enumerate files successfully. I need to c开发者_JAVA百科onfigure can't access outside web site directory. Only use inside files and folder
How to do that?
the code you are showing does not mean that external individuals can access files on your server, all that it shows is that a program RUNNING on your server can access files on the server which make sense.
If you want to prevent a program from accessing those files then add security permissions to them for a user that is not the user that runs the program you want to prevent from accessing them.
If you are looking to secure a directory look at using .htaccess (very basic security) or take into account Alex's solution
You could create a new user that has limited permissions and set to run app pool under this user.
To change Identity of an AppPool (i.e. Specify what credentials the App Pool is running as)
- Open IIS
- Select Application Pools in the Connections tree
- Select the Application Pool
- Right Click and select Advance Settings.
- Find Process Model / Identity. The default may read ApplicationPoolIdentity
- Click to the value (e.g. ApplicationPoolIdentity)
- Click the ellipsis that appears to the right
- Select a built in account or click custom account
- If Custom account was chosen, click Set and specify the Windows account and password
- Click OK to close the Set Credentials dialog
- Click OK to close the Application Pool Identity dialog
- Click OK to close the Advanced Settings dialog.
- Recycle the Application Pool.
You can also set identity in the web.config file:
<system.web>
<identity impersonate="true"
userName="UserName"
password="Password"/>
</system.web>
精彩评论