ASP.Net using wrong web.config for virtual directory - .net-4.0

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>

Related

Apache mod_mono settings for multiple MVC apps without editing apache config

I am setting up a mono server using Apache and mod_mono on the Raspberry PI 3 running Raspbian Jesse. I already have mono and mod_mono installed and functioning properly.
This is my desired folder structure
/var/www/html
App1
App2
I would like to configure Apache so that I can simply copy a new .NET mvc3 app into a folder directly beneath /var/www/html, (i.e. /var/www/html/App1), and each of those applications will automatically start working as MVC3 apps without having to add an entry to the apache config for each application.
MonoAutoApplication enabled does not work in this case because I am not serving .aspx pages (or any other .net file), but rather these are MVC applications.
The benefit of this approach is that I can keep this config file with each application in version control. Then when starting a server from scratch, there is less configuration that needs to be done when deploying the apps.
Any ideas on how to handle this?
A few assumptions are made here.
Apps will only be published directly beneath /var/www/html. For example, /var/www/html/app1, /var/www/html/app2
Each app will provide a mod_mono.conf file in its root folder. For example, /var/www/html/app1/mod_mono.conf
The mod_mono.conf for each app must know the absolute path to the app.
The apache server must be reloaded after deploying a new app. There's not really a way around this.
At the end of apache2.conf, add the following:
/etc/apache2/apache2.conf
#define the default mono server
MonoServerPath default /usr/bin/mod-mono-server4
#include all config files from all mono apps
IncludeOptional "/var/www/html/*/mod_mono.con[f]"
#prevent web access to mod_mono.conf files
<Files ~ "mod_mono.conf">
Order allow,deny
Deny from all
</Files>
and then for each application, add this mod_mono.conf, changing the path to the folder accordingly
/var/www/html/app1/mod_mono.conf
AddMonoApplications default "/app1:/var/www/html/app1"
<Location /app1>
SetHandler mono
</Location>

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

Running jsp files from /srv/http using Apache HTTP server and Tomcat

I'd like run jsp files directly from /srv/http without deploying them the Tomcat-way. For example, I want to be able to create symbolic link to my webapp directory (e.g. /home/user/myapp/) in /srv/http and access some app's page through http://localhost/myapp/page.jsp.
Is this possible and how would I set this up?
NOTE: This is not for production. We have to use JSP at university and I want to be able to quickly test my pages.
Open the server.xml of your Tomcat. Assuming if your are using Tomcat 6.x+ then it would be at /tomcatDir/conf/server.xml.
Make an entry with your path
<Context path="/myapp" docBase="yourPathGoesHere" debug="0" reloadable="true" />
Restart Tomcat if already running.
What I did at the moment was creating a symlink in /var/lib/tomcatX/webapps to my project path. This is not the answer I was looking for though, but it is a way to deploy an app without much work.
(X in the above path means your Tomcat version)
If you set <Host name="localhost" appBase="/srv/http"> then all of the directories in it will be deployed as web applications.
If you want /srv/http to be the ROOT application/directory add a file: tomcat/conf/Catalina/localhost/ROOT.xml
with the Context docBase="/srv/http", rather than adding a Context definition to server.xml - this has been strongly discouraged for years.

How to separate static content on ASP.NET MVC in Apache mod-mono

I have already a project that built top of the ASP.NET MVC 2.0 and it's working.
I tried to run it on Ubutuntu 10.4 Server on Apache2 and Mod mono.
As you know, when you created a new project on VS.NET it creates a Content folder for holds static content such as css, js, images etc.
Also my project has working with Forms authentication, and i separated some path of my project with below location element in web.config.
<location path="Content">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
But above configuration hasn't worked on Apache.
The question is; how can i pass authentication for static contents on apache - mod mono ?
Thank you

IIS6 Virtual Directory not accessible as an app

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