One IIS site, Two applications with different .NET versions - asp.net

I porting an old site into MVC 4 and I have it working so far. However there is also a third party forum which we use which isn't changing. In IIS 7 I created a new Application for the forum and it also has its own app pool (MVC is .NET4 and forum is .NET 2).
The applications are in different physical directories on the server, and here's what the IIS directory structure looks like with ForumApp being the sub-application:
\RootMVCSite\
\RootMVCSite\bin
\RootMVCSite\[OTHERMVCFILESANDFOLDERS]
\RootMVCSite\web.config
\RootMVCSite\ForumApp\
\RootMVCSite\ForumApp\bin
\RootMVCSite\ForumApp\[OTHERFORUMAPPFILESANDFOLDERS]
\RootMVCSite\ForumApp\web.config
However, when I go to the forum I get the following error:
Parser Error Message: Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive.
Line 20: <system.web>
Line 21: <compilation targetFramework="4.0" />
The confusing part is that it is looking in the web.config for the root MVC site rather than the forum site where the sub-application is pointing. What do I need to do in IIS or web.config to fix this? Is there a way to prevent the sub-app from looking at the root site's web.config?

I figured it out. By wrapping the offending configuration sections with the location tag, those settings would be ignored by any child applications.
<location path="." inheritInChildApplications="false">
<system.web>
<compilation targetFramework="4.0" />
</system.web>
...
</location>
If there's anything I should be wary of regarding this solution, please chime in and suggest any improvements or advice!

Check the application pool for that site in IIS and make sure it targets .NET Framework 4.0. By default a new application pool will be set to .NET 2.0.

Related

Asp.Net httphandler cause 500 (Internal server error)

I want to add a handler to my existing web form application.
Following this walkthrough in web.config I've added:
<configuration>
<system.web>
<httpHandlers>
<add verb="post" path="redirect.ashx" type="RedirectHandler"/>
</httpHandlers>
</system.web>
</configuration>
I've created a Generic Handler (called RedirectHandler.ashx) in App_Code folder,
but when I run the application (VS2017) it causes a 500.
The tutorial makes a distinction between registering in IIS 6.0 and IIS 7.0. I'm not sure which one applies to me considering that VS runs IIS Express 10.0. Anyway, I've already tried both with poor results.
I'm a noobie to web forms but it seems pretty straightforward. I don't understand why it doesn't work.
EDIT: Creating a new project and adding httphandlers doesn't cause any issue. So it must be some configuration with my current project but I have no idea what may cause the error.
EDIT 2: To answer at the 500 error, the problem was caused by the wrong "type" in httpHandlers. Type should be "Namespace.class".
This post really helped me to figure out a few things.

Is there a "release" configuration for ASP.NET Web Sites?

I use Visual Studio for Website development (VS 2010 Ultimate and VS 2012 Professional). To be more specific, I created this website by File > New Web Site, so I do not believe this is a project.
While developing the website, I have debug="true" enabled in the web.config file. When I publish, I manually change to debug="false".
<configuration>
<system.web>
<compilation debug="true" strict="true" explicit="true" targetFramework="4.5">
</system.web>
</configuration>
There are two config files in the solution: "web.config" and "web.Debug.config".
This is what the various forum articles and "Programming ASP.NET" books say to do, but I wonder if there is a way to have debug="true" for local development and automatically switch to debug="false" when using Build > Publish Web Site so I don't have to manually change the web.config file?
According to this forum answer, "There is no way to have a Release configuration for your website."
Keeping in mind that this is a Web Site and not a project, it looks like adding another config based on comment suggestions might not be possible. A possibly valid answer is "no, it is not possible in this context."
Is there another way to achieve the intended outcome without using the current workaround of manually changing the debug setting?
Sorry, it's related to it being a "web site" type project, which aren't compiled:
Configuration of publishing an ASP.NET web site
To quote the previous responder above:
"Web Site projects don't have the Release configuration available, but it makes no difference since they are not compiled. Web Application projects, on the other hand, do get compiled and have both configurations available."
According to the available references, for "ASP.NET Website" it is not possible to have a separate release configuration.
So the answer to the posed question is no: it is not currently possible. Manually changing the debug attribute when you publish and then changing it back is the only option in that case.
How can you proceed? If you really need to have a release configuration and a debug configuration, the a possible option is Converting a Web Site Project to a Web Application Project. While not a direct answer to the presented question, it is an alternative.
For some projects I've set up an Environment appSetting and scoped all other keys off of that Environment.
For instance:
<add key="Environment" value="Development"/>
<add key="Development.Title" value="My Dev App"/>
<add key="Production.Title" value="My Production App"/>
<connectionStrings>
<add name="DbContext.Development" connectionString="Initial Catalog=DatabaseDev;...."
providerName="System.Data.SqlClient" />
<add name="DbContext.Production" connectionString="Initial Catalog=DatabaseProd;...."
providerName="System.Data.SqlClient" />
</connectionStrings>
Then you would create a Configuration class that would pull appSettings and connectionStrings by looking for:
appSetting
string.Format("{0}.Title", ConfigurationManager.AppSettings["Environment"])
connectionString
string.Format("DbContext.{0}", ConfigurationManager.AppSettings["Environment"])
Not perfect but this will let you only have to replace one web.config value instead of a bunch without the help of the Publish config transform.

Is it possible to host an aspx (.NET 4.0) website locally on Windows 8 Enterprise?

As the title states is it possibly to host a dynamic (that would be .aspx correct?) website locally (IIS 8) on a computer running Windows 8 Enterprise? I've installed all the IIS components, added the website as many guides on Google will show but I get error 9 as stated here:http://support.microsoft.com/kb/942055
my web.config is as follows:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="false" targetFramework="4.0"/>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
I also have the correct version set for the site (.NET 4.0) and tried resetting all feature delegations. At this point I'm thinking of just doing a cheese puff solution and just running the site via the built in server within Visual Web Developer.
"Stock" ASP.NET Web.Config file
When I create a standard, empty ASP.Net Web Forms Application targeting .NET Framework 4.0, here's the standard Web.config file that's generated:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections />
<connectionStrings />
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" defaultUrl="~/" />
</authentication>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
EDIT: I removed the Membership, Role, Profile, and SessionState sections that were previously here. These aren't, strictly, required but are part of the standard Empty ASP.Net Web Forms Application template to help you get started quickly. What is shown above is the minimum Web.config you need.
NOTE: Don't worry about the debug="true" in the <Compilation /> element. You should have that attribute set to false in production anyway.
I Suspect it's your IIS Configuration
After re-reading your question, I suspect that you haven't properly configured IIS to host the site properly.
First, I want to start by saying that there's Internet Information Services (IIS), the actual web server, that can be installed on Windows 8 as well as server OSes such as Windows Server 2012. There is also IIS Express, used for development and which is a replacement for the old Development Web Server (code-named Cassini) in VS2008 and VS2010 (prior to SP1 when IIS Express was made available through an additional installation).
It sounds to me like you have installed IIS under Windows 8 Program and Features. Now you need to create a site in IIS that points to where your web application is located on your hard disk.
Open IIS Manager
Expand your machine name in the Connections pane on the left.
Expand the Sites folder. There should already be a site called Default Web Site.
Right-click the Sites folder and choose Add Website....
Give the site a name. Choose the DefaultAppPool for now (you can change it later).
Under Physical path, browse to where your web site/application is located on your hard disk.
Click OK.
There are other options on that page and you can find help on them at MSDN. That may be enough to get you started, though.

Migrate ASP from root to subdirectory

I'm in the process of converting an existing ASP website into PHP while retaining the ASP website as an older version. Since I'm not an ASP developer, I thought it would be simple as moving the contents of the root directory into its own directory that I've labeled as v1.0 so that the ASP version can be viewed by going to www.mysite.com/v1.0 while the new PHP version (v2.0) can be viewed by going to www.mysite.com
Herein lies the problem. Doing this causes flags all kinds of errors (all related to "Server Error in '/' Application. Runtime errors"). The best I can figure out is that the web.config file needs to be tweaked in the v2.0 directory. Can any of you ASP experts recommend a simple solution to make this happen? I would like to have an empty root directory if possible since the new v2.0 version will be in all PHP and want to "self contain" the ASP version within the v1.0 directory as much as possible.
Thanks!
After a bit of wrangling, finally figured out that I needed to set up v1.0 as its own application under the IIS control panel. Once that was done, then all the contents of the root directory could be moved over to the v1.0 sub-directory and viewed via www.mysite.com/v1.0 -- thanks to Sean! for his help!
Most Classic ASP pages use Server Side Includes, if the site is using a SSI such as:
<!-- #include virtual = "include-file.inc" -->
, then you will need to change all of these to be
<!-- #include virtual = "v1.0/include-file.inc" -->.
I assume that you are using IIS 7 or IIS 7.5, since you are not seeing the actual error, you will need to modify your web.config file.
<configuration>
<system.webServer>
<asp scriptErrorSentToBrowser="true" />
<httpErrors errorMode="Detailed">
</system.webServer>
</configuration>
Reference:
http://learn.iis.net/page.aspx/564/classic-asp-script-error-messages-no-longer-shown-in-web-browser-by-default/
Update
Since it now sounds like you are using ASP.NET, you would need to change your web.config as below to see the full error:
<configuration>
<system.web>
<customErrors mode="Off" />
</system.web>
</configuration>

Can I run a .NET 2 application below a .NET 4 website with multipleSiteBindingsEnabled

I have a website with an app pool running .NET 4 on IIS 7 and it has the following setting in system.ServiceModel in the Web.config:
serviceHostingEnvironment multipleSiteBindingsEnabled="true"
The problem I have is that I want to be able to run an application below this using a .NET 2 app pool. When I try this the app complains that it has an unknown attribute for multipleSiteBindingsEnabled. I can't see a way to hide this .NET 4 attribute in the Web.config of the .NET 2 application. Is there any way to do this?
The problem is the different versions of .net use different aspnet_isapi.dll to do there work and so are incomparable with each other.
All I can think of which might work is to put your .Net 2 application in its own virtual directory in IIS and set it with the right .Net version and on a different app pool. Try placing the virtual directory in a different location on the file system from the main site.
Even this might not work though. At which point you would need to place the .Net 2 application on its own sub domain of the master website.
Inside your .NET 4 application you should try to use:
<location path="Net2VirtualFolderName">
<system.web>
<compilation debug="false" />
<!-- custom config -->
</system.web>
</location>

Resources