Deny access to a folder in ASP.NET - asp.net

is it possible to prevent browsing of a folder contents in an ASP.NET web application other than creating a default page, say using web.config?
I would like to avoid using IIS for this if possible.
Thanks

If you are using IIS7, you can use web.config files for this. Specify a <location> tag for the desired folder, and give it a <directoryBrowse> sub-tag, ie:
<location path="path to your folder">
<system.webServer>
<directoryBrowse enabled="false" />
</system.webServer>
</location>

The previous answer system.webServer -> directoryBrowse is new and can be used when your site is running under IIS7 (be it debugging or otherwise) only, it will not work in IIS6. In IIS6 you need to do it using the IIS management console.

Related

I want to url redired in asp.net using web.config

I have one or more than one url like http://vfiresolution.in/pdf/p.pdf. And I want to redirect the above url to http://vfiresolution.in/page.aspx?id=1.
I am using the below given code. My code is working on local host. But If i publish my code on shared server code not working.
my code is
<configuration>
<location path="pdf/p.pdf">
<system.webServer>
<httpRedirect enabled="true" destination="http://vfiresolution.in/page.aspx?id=1" httpResponseStatus="Permanent" />
</system.webServer>
</location>
</configuration>
http://www.iis.net/configreference/system.webserver/httpredirect
check the iis
(httpredirect)
Compatibility
The httpRedirect section of web.config is compatible with IIS 7 (w2k8) and IIS 7.5 (w2k8 r2).
Web.config files are deeply integrated with IIS 7.x.
The httpRedirect directives listed will apply to all files and directories (php, jpg, png, htm, etc), not just asp.net files.
While some web.config sections sometimes require that the containing directory is set as an application, this isn't one of them.
A simple web.config with a httpRedirect section may be placed in any directory, and the directory does NOT need to be set as an application.

EPIserver no CSS for the UI Admin section

After moving a EPI6 site to my local machine and reconfiguring it for IIS7.5 (instead of IIS6) i have a problem.
The UI Admin/Edit backend has no CSS. I suspected this was due to the virtual path mapping and i found that they where all mapped to %ProgramFiles% but on my local machine EPI is installed on %ProgramFiles(86)%. So i changed it and made sure all physical paths worked. They did.
So i felt smart and expected the CSS to load properly but no change happened.
I have tried ctrl F5 to see if its a caching problem, i have restarted the IISExpress. But still no CSS.
Any tips on something i might have forgotten?
Check using Firebug Net-tab or equivalent F12 web browser tool to see exactly which paths don't respond correctly.
Check permissions on disk for the Program Files directories in questions.
Compare Web.config to a default EPiServer IIS7 web.config to see that you have all handlers in the correct place.
I solved this.
It was not a problem of rights, but rather a configuration error. When uppgrading fom using IIS6 to IIS7.5 i forgot changing in the Web.Config:
IIS6 version
<location path="App_Themes/Default" />
to:
IIS7.5 version
<location path="App_Themes/Default">
<system.webServer>
<handlers>
<clear />
<add name="wildcard" path="*" verb="*" type="EPiServer.Web.StaticFileHandler, EPiServer" />
</handlers>
</system.webServer>
</location>

Is "management" section not allowed in web.config?

I'm trying to add users to IIS Manager via web.config, but whenever I add the following lines, the web site stops working and says web.config is not valid.
The web site works if I add those lines in administration.config, but I like to keep the scope small by sticking with web.config.
<system.webServer>
<management>
<authorization defaultProvider="ConfigurationAuthorizationProvider">
<authorizationRules>
<scope path="/MyApp">
<add name="domain\user" />
</scope>
</authorizationRules>
</authorization>
</management>
</system.webServer>
A simple Google search can answer your question.
IIS Management element
From that page:
Note: The settings in the management element can only be configured in the Administration.config file.

How to set Allow Parent Paths in IIS Express Config using asp directive

This is a continuation of a answered question in the following link:
How to set Allow Parent Paths in IIS Express Config
I am running a classic asp web site in IISexpress.
The same web site is also used in IIS 7.5 in a w7 pro and works fine enabling the parent paths in the IIS configuration of the web but trying to use the web.config in IISExpress does not work
The problem that I am experiencing is that in the suggested web.config in order to enable the parent paths:
<configuration>
<system.webServer>
<asp
enableParentPaths="true"
bufferingOn="true"
errorsToNTLog="true"
appAllowDebugging="true"
appAllowClientDebug="true"
scriptErrorSentToBrowser="true">
<session allowSessionState="true" />
<cache diskTemplateCacheDirectory="%TEMP%\iisexpress\ASP Compiled Templates" />
<limits />
</asp>
</system.webServer>
</configuration>
I get a 500 error every time that I try to use any asp tag
If I remove the asp tag it all works fine,
Anybody has a clue?
TIA
You have not read carefully. The configuration file that mentioned isn't web.config. It is applicationHost.config. As a shotcut:
Press Win+R
type
notepad "%userprofile%\Documents\IISExpress\config\applicationhost.config"
hit ⏎. This will open the host configuration file with notepad. You need to find your web site's section. It's something like <location path="YourSiteName"> ... </location>. Look inside that node, find the <asp> section and change with yours. Finally, don't forget to remove the asp section from web.config.

IIS7: disabling HttpModule in subapplication - sites, application and virtual directories

I have a few aspx files in a "Cache" folder in my application and I do not want HttpModules to run for those files in that folder. I tried having a web.config in subdirectory but learned that HttpModules take the root web.config and not that of the subdirectory.
Reference 1, Reference2. So I decided to have this directory as a sub application as per suggestion here and here.
So I configure my application,then "add application" , map it to this directory, which already was inside this application and boom, it fails. It works for a static html file, but aspx files are not available.
My question is, how do I configure a sub-application in IIS7 so that the sub-application can have its own web.config and there I can disable HTTPModules of the root application
Edit:In fact I tried creating a subapplication within my main application and it did not work. Can some one point me to any article on how to configure a sub-application in IIS7 ?
Edit2: adding the error image. So how should I configure the child app pool. The child app runs in the same app pool as that of parent
Edit3: sorry, the child was running on a different app pool. A generic app worked(without modules). I am marking the answer after I try out the modules.Thanks for your help guys. There is something specific in my parent app web.config, which I am going to hunt down now.
EDIT: Actually both the answers provided below are correct. If you are using IIS7 integrated mode your modules should be in system.webServer and if IIS7 - classic mode your modules (and handlers?) should be in system.web
JKG has the right answer for IIS6, but the syntax is a little different in IIS7:
<system.webServer>
<modules>
<remove name="MyModule"/>
</modules>
</system.webServer>
The web.config will always inherit from its parent if it's in the same web application but you can clear the entire thing or remove an item like so:
From the child web.config (clear all or remove an item)
<httpModules>
<clear />
<remove name="MyModule"/>
</httpModules>
From the parent config by using the location tag...
<location inheritInChildApplications="false">
<system.web>
<!-- ... -->
</system.web>
</location>
http://www.jaylee.org/post/2008/03/Prevent-ASPNET-webconfig-inheritance-and-inheritInChildApplications-attribute.aspx

Resources