IIS6 Virtual Directory not accessible as an app - iis-6

I have a WinSrv2k3 box with IIS6 hosting a series of sites, one of which is a VB/.NET2 site. Inside this I have created a virtual directory and pointed it at a very simple C#/.NET3.5 site's directory. I was expecting the site to allow me to view the pages as a normal site (there is only one ASMX in the virtual directory) but when accessing the page from a browser, I get:
Server Error in '/TestVbSite' Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Could not load file or assembly 'IMSControls' or one of its dependencies. The system cannot find the file specified. (D:\sites\TestVbSite\web.config line 211)
Source Error:
Line 209: </httpHandlers>
Line 210: <httpModules>
Line 211: <add name="UrlRewritingModule" type="IMS.Controls.HttpModules.UrlRewritingModule, IMSControls" />
Line 212: </httpModules>
Line 213: </system.web>
Source File: D:\sites\TestVbSite\web.config Line: 211
The issue I see there, is that the web.config throwing the exception appears to be the parent web site's .config, not the web.config in the virtual directory. But I don't understand why.
When accessing regular pages within the website (not under the virtual directory) they render and perform as normal, indicating that the IMSControls DLL is unable to load from the virtual directory, but again, I don't understand why this would even be involved in the process.

Ok, well, after some false starts, heavy googling gave me the correct thing to look for: web.config inheritance.
Basically, to stop a virtual directory from inheriting the attributes of it's parent site's web.config (and therefore any problems from it) the parent site's web.config needs to have its <system.web> element wrapped in a new (to me) tag:
<location path="." inheritInChildApplications="false">
<system.web>
...
</system.web>
</location>
Useful links:
http://forums.asp.net/t/1164283.aspx
http://dotnetslackers.com/Security/re-55457_Stopping_ASP_NET_web_config_inheritance.aspx
http://msdn.microsoft.com/en-us/library/ms178685.aspx

Related

Require SSL on MVC View

With web forms I can designate an individual ASPX page to require SSL and IIS will ask the user to pick a certificate from their CAC. However, in IIS Manager on the server for an MVC site, the individual views are not listed so I cannot require SSL for a particular view. Is there any way to do this?
My web.config has been changed:
<location path="FileSharing/Welcome" allowOverride="true"></location>
<location path="FileSharing/Index" allowOverride="true">
<system.webServer>
<security>
<access sslFlags="Ssl,SslNegotiateCert,SslRequireCert"/>
</security>
</system.webServer>
Error 500.19
Error Code
0x80070021
Config Error
This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".

Sitecore redirect on errors

I know that I can extend Sitecore.Pipelines.HttpRequest.ExecuteRequest and override methods like RedirectOnItemNotFound to redirect to my custom 404 page etc. I was wondering if there is way to redirect to a custom page (that would sit in sitecore) for all errors except 404 and 500?
There is a RedirectOnNoAccess method for 403 error I guess, but I am looking for way to redirect on all errors like 400, 401, 403, 405 etc.
Sitecore v7.2
Cheers
You don't need to extend the ExecuteRequest processor, there are settings in the Sitecore section of config to handle these:
<!-- ITEM NOT FOUND HANDLER
Url of page handling 'Item not found' errors
-->
<setting name="ItemNotFoundUrl" value="/sitecore/service/notfound.aspx"/>
<!-- LINK ITEM NOT FOUND HANDLER
Url of page handling 'Link item not found' errors
-->
<setting name="LinkItemNotFoundUrl" value="/sitecore/service/notfound.aspx"/>
<!-- LAYOUT NOT FOUND HANDLER
Url of page handling 'Layout not found' errors
-->
<setting name="LayoutNotFoundUrl" value="/sitecore/service/nolayout.aspx"/>
<!-- ACCESS DENIED HANDLER
Url of page handling 'Acess denied' errors
-->
<setting name="NoAccessUrl" value="/sitecore/service/noaccess.aspx"/>
Update these values to point to the correct path. This can be a Sitecore item path, e.g. /errors/404 as long as that item exists in Sitecore. It's slightly annoying that a url parameter is added to the path, you will need to extend the processor if you want to get rid of this though. If you have a multi-site implementation then this will still work but you need to make sure that the structure is the same for all sites, since you are using a relative path. The error manager module is essentially a wrapper around these same settings, but it is better in that it is able to handle multi-site and shows the error page without making a 302 redirect first.
If you need to handle other errors then fallback to using the errors section in config to define those. The values can also be set through IIS (although it just updates the web.config anyway)
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly" defaultResponseMode="ExecuteURL" defaultPath="/errors/404">
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="405" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/errors/404" responseMode="ExecuteURL" />
<error statusCode="405" prefixLanguageFilePath="" path="/errors/405" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="/errors/static/500.html" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
http://www.iis.net/configreference/system.webserver/httperrors
https://msdn.microsoft.com/en-us/library/ms690497(v=vs.90).aspx
These can be in Sitecore by setting the URL path of an Item or static HTML files on disk, and again it works in multi-site as long as the structure is the same for all sites since the path can be relative. It is generally recommended that the 500 page is a static HTML page otherwise there is the possibility of an infinite loop (e.g. database goes down, show 500, fetch content from Sitecore, but database is down...).
Even if you use the Error Manager module, or use the Sitecore settings, I recommend that you have a 404 and 500 page defined in config. By default Sitecore will only handle dynamic and extentionless URL requests, so if a request is made for /file.txt, /style.css, /script.js or /document.pdf then you will get a standard IIS error page.
<preprocessRequest>
<processor type="Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions, Sitecore.Kernel">
<param desc="Allowed extensions (comma separated)">aspx, ashx, asmx</param>
<param desc="Blocked extensions (comma separated)">*</param>
<param desc="Blocked extensions that stream files (comma separated)">*</param>
<param desc="Blocked extensions that do not stream files (comma separated)"></param>
</processor>
</preprocessRequest>
You could allow all requests to go through Sitecore but this seems a bit heavy handed and you're making it run through additional pipelines. Setting the above will mean your static content is also gracefully handled.
You can definitely use the execute request pipeline to handle 403 and 401 errors as this pipeline is called early enough.
There is a great module that already does this on the marketplace, which you may be able to adapt to your needs.
https://marketplace.sitecore.net/en/Modules/Sitecore_Error_Manager.aspx
http://ctor.io/handling-404-and-other-errors-with-sitecore-items/

How to preserve Apache Tomcat7 configuration files when reinstalling application

I am using Apache Tomcat7 for one of my projects and in order to store some container specific configuration, I am using an XML file under the /etc/tomcat7/Catalina/localhost/ directory (in linux). For example /etc/tomcat7/Catalina/localhost/my-app.xml if the app in question is called my-app.
When I reinstall (update) the application, the afore mentioned file, seems to be deleted during the installation process. Is there any way to preserve this file?
Yes! Have done this mistake quite some time.
There are several conditions (like changing the war file, deleting the webapp or replacing it with new content) under which tomcat will undeploy the context including removing the context file.
You should stop your server before making any changes like changing your war file. If you try to edit or move the deployed war file the corresponding configuration in conf/Catalina/localhost/ will get deleted.
If you do not wish this behavior you can edit the server.xml file located in conf/ directory.
Change
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
and make autoDeploy="false"
For more details you can refer to Apache Tomcat Configuration Reference

IIS Authentication in web.config

In our project, a user can upload documents to a directory. The problem is that a user cannot access those files via the URL.
After playing around with permissions in IIS, I was able to download a file by changing the permissions on the file (or folder) to allow "Read" by IIS_IUSRS. My issue is that the folders are also dynamically generated and I do not want to manually have to go through and change the permissions on each.
I'm attempting to get the web.config file to allow reading of these files, but I cannot get the proper configuration.
In the site's web.config file I have:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<location path="path/to/upload/directory">
<system.webServer>
<security>
<authentication>
<windowsAuthentication enabled="false" />
<anonymousAuthentication enabled="true" />
</authentication>
</security>
</system.webServer>
</location>
</configuration>
However upon accessing the file again, I get a 500.19 error:
AnonymousAuthenticationModule
This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default
(overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
Following this answer, I set AnonymousAuthenticationModule to lockItem="false", anonymousAuthentication to Allow in applicationHost.config, and restarted the server. After all of that, I still get the same 500.19 error.
When you say the folders are generated dynamically, do you mean generated through code? If so, you could make sure the parent directory has the required permissions and then set the permissions on its subdirectories to "inherit". For a file, it would be
Dim perms = File.GetAccessControl(targetFile)
perms.SetAccessRuleProtection(False, False)
File.SetAccessControl(targetFile, perms)
I expect that you can find the equivalent for a directory.

ASP.Net using wrong web.config for virtual directory

We're running IIS 6 on Windows Server 2003 R2.
We want to add a virtual directory that runs under .NET 4.0 to a site that runs under .NET 2.0. We've given the virtual directory its own app pool, and we've configured the virtual directory to run under 4.0.
The parent site works fine, but the virtual directory throws errors that reference the parent site's web.config file. We need the virtual directory to use its own web.config file.
The GUI in the IIS Manager says that the virtual directory is using its own web.config file, but the error messages we get refer to items in the parent's web.config file.
I'm not sure how to solve the problem. My best lead so far is from a post on another site said that the problem could be solved with something like this:
<location path="." inheritInChildApplications="false">
</location>
Again, I'm not sure this will fix things, and I'm not sure how to figure out where to put it or what it ought to contain. The parent site is built on top of a CMS system, and its web.config file is reasonably complex.
I got this to work, so I want to leave the answer for the next person.
The location tags I mentioned in my question did the job. I got them to work by using them to enclose a system.web section:
<location path="." inheritInChildApplications="false">
<system.web>
.
.
(the stuff that made the site in the virtual directory break)
.
.
</system.web>
</location>