IIS 10 ServiceStack .Net4.8 404 - asp.net

I recently upgraded to .Net Framework 4.8 and ServiceStack 5.6.0 on one of my projects.
When I run it in Visual Studio through IIS express it works fine, but in IIS I get the following.
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Anyone have similar issues?
Windows 10 - IIS 10
Below is my web.config: (the sections I think is relevant)
<system.web>
<compilation targetFramework="4.8" />
<pages controlRenderingCompatibilityVersion="4.0" />
</system.web>
<system.webServer>
<directoryBrowse enabled="true" />
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add path="*" name="ServiceStack.Factory"
type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*"
preCondition="integratedMode" resourceType="Unspecified"
allowPathInfo="true" />
</handlers>
</system.webServer>
Another thing this is my versions of ServiceStack
<package id="ServiceStack" version="5.6.0" targetFramework="net48" />
<package id="ServiceStack.Client" version="5.6.0" targetFramework="net48" />
<package id="ServiceStack.Common" version="5.6.0" targetFramework="net48" />
<package id="ServiceStack.Interfaces" version="5.6.0" targetFramework="net48" />
<package id="ServiceStack.Text" version="5.6.0" targetFramework="net48" />
Troubleshooting:
I turned my internal logging on and I am able to see logs from the Global (method Application_Start) it calls the ServiceStack AppHost().Init() which also runs without error and does the Configure().
My Application_Start:
protected void Application_Start(object sender, EventArgs e)
{
log4net.Config.XmlConfigurator.Configure();
Logger.LogInfo("Global Application_Start prior AppHost().Init()");
new AppHost().Init();
Logger.LogInfo("Global Application_Start done");
}
My AppHost Configure()
public override void Configure(Funq.Container container)
{
try
{
Logger.LogInfo("AppHost Configure");
//plugins
Plugins.Add(new CorsFeature());
Plugins.Add(new PostmanFeature());
Plugins.Add(new ValidationFeature());
}
catch (Exception ex)
{
Logger.LogException(ex);
if (ex.InnerException != null)
throw new Exception(ex.InnerException.Message);
else
throw new Exception(ex.Message);
}
}
Both the above methods execute without errors, needless to say seeing that this project does run successful in IIS express through Visual Studio.
I am certain its an IIS or config error I am just not sure what, my .Net 4.7.2 projects run without issues.

The problem seem to be that I am hosting 2 application under one website in IIS, normally it is not an issue, but in my scenario my one website is .net 4.8 and the other one .net 4.7.
To resolve I created a website for each application and that solve my problem.
In the past I could mix .Net4.5 and .Net 4.7 application but it seems to not work when working with .net 4.8.

Related

Custom handlers for ASP.NET 2.0 Website in Classic mode in IIS 8.5 throwing 500 error

I have ASP.NET 2.0 website running in Classic Mode.
Server 2001/IIS 8.5.
I get this error when calling custom handler (something.abc).
I have my handler(something.abc) added to <system.webServer><handlers> section
<add name="Something.abc" verb="GET,HEAD" path="something.abc" type="ABC.MyHttpHandler, ABC" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified"/>
It was working fine in local IIS Express.
On Server when I changed the Application Pool setting: Enable 32-bit Applications= True it started working.
Question: Why I had to turn 32-bit mode and is there any way I can make it work without enabling 32-bit?
I ran into this problem with an application running on a new Windows Server 2016 box with IIS 10.
It was working on the old Server 2012 box because that one had the 32-bit Oracle client installed, but the new server had the 64-bit Oracle client installed, and I was therefore unable to set Enable 32-bit Applications= True without causing other problems.
The worker process was also set up to use Classic pipeline instead of Integrated, another setting that I could not change in order to get this to work. ASP.NET was properly installed too. (i.e. this solution did not help me.)
I had:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="Something.abc" verb="*" path="something.abc" type="ABC.MyHttpHandler, ABC" resourceType="Unspecified" />
To solve this issue I added BOTH of these attributes (it did not work with only one or the other):
modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll"
i.e. final result was:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="Something.abc" verb="*" path="something.abc" type="ABC.MyHttpHandler, ABC" resourceType="Unspecified" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" />

Log4Net working locally but not on remote Azure DB

I locally develop an ASP.NET MVC application and use Log4Net to log message on the local database with the following connection string (log4net.config):
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="Data Source=.\;Initial Catalog=MyDatabase;Integrated Security=True" />
This is perfectly working (database entries are appearing in the Log table).
Now I'd like to log to remote azure database server, so I just changed the connection string into following:
<connectionString value="Data Source=mydb.database.windows.net,1433;Initial Catalog=MyDatabase;User ID=username#mydb;Password=mypassword;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" />
I inserted my IP address in the firewall (as proof I can connect via SQL Studio on my machine to the azure db instance).
When debugging the application I don't see any exception caused by log4net.
I use castle-windsor to inject the ILogger where needed, here is my Installer:
public class LoggerInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.AddFacility<LoggingFacility>(f => f.UseLog4Net().WithConfig("Configuration\\log4net.config"));
}
}
The database on the azure DB instance is the exact copy of the local one (same create script).
But nothing appears in the remote database. What am I doing wrong? How can I find out the problem?
Thanks a lot
Log4net will never throw an exception if it fails. It is designed to not interact with you application. The fastest way of finding why lognet is not logging is by enabling the interal log4net logging:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="log4net.Internal.Debug" value="true"/>
</appSettings>
</configuration>
OR
<configuration>
...
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add
name="textWriterTraceListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\tmp\log4net.txt" />
</listeners>
</trace>
</system.diagnostics>
...
</configuration>

Receiving 'This operation requires IIS integrated pipeline mode.' error when adding httpModule to VS web project

Can someone shed some light on what's going on? I have a website created using VS 2010. The following code is added by default by VS when adding an httpModule. When I run the app through Casseni, the highlighted line throws the error "This operation requires IIS integrated pipeline mode."
public void Init(HttpApplication context)
{
// Below is an example of how you can handle LogRequest event and provide
// custom logging implementation for it
**context.LogRequest += new EventHandler(OnLogRequest);**
}
#endregion
public void OnLogRequest(Object source, EventArgs e)
{
//custom logging logic can go here
}
My web.config file was updated as such:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpModules>
<add name="GlobalModule" type="MyApp.Global.GlobalModule, EduCarePro"/>
</httpModules>
</system.web>
<system.webServer>
<modules>
<remove name="GlobalModule"/>
<add name="GlobalModule" type="MyApp.Global.GlobalModule, EduCarePro" preCondition="managedHandler"/>
</modules>
</system.webServer>
Is there something else that must be configured in the Web.Config to prevent this error??
The answer to this question is that Visual Studio's development web server does not support this functionality. You must run this code on an a machine running IIS.
TAKEN FROM (And Worked for me too as i had same problem)
Link

new handler triggers debug failure in visual studio

I have an existing asp.net website that works. When I (F5) debug it works. However, I am working on a new IHttpHandler for the site. As soon as I add the <system.webServer><handler></handler></system.webServer> section to the web.config visual studio refuses to F5 debug with the error:
Unable to start debugging on the web server. The web server could not
find the requested resource.
With the handler in place, if I attach-to-process then I can successfully attach to the process (and with the System.Diagnostics.Debugger.Break(); line I can step through the handler's code). I also added my handler to a different website and was able to reproduce this issue.
My Environment: .NET 4.0, Visual Studio 2012, using local IIS in integrated mode on Windows 7.
While trying to sanitize the code to paste here, I ended up commenting out everything in my handler except the boiler-plate, and the issue still occurs. Here are the code snippets:
The handler class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MySvc
{
public class MyServiceHandler : IHttpHandler
{
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
//#if DEBUG
// System.Diagnostics.Debugger.Break();
//#endif
}
}
}
and the web.config:
<?xml version="1.0"?>
<configuration>
<appSettings>
<clear/>
<add key="A1" value="sanitized"/>
<add key="A2" value="sanitized"/>
</appSettings>
<connectionStrings>
<clear/>
<add name="MyDatabase" connectionString="sanitized"/>
</connectionStrings>
<system.web>
<compilation debug="true"/>
<httpRuntime maxRequestLength="1048576" executionTimeout="3600"/>
<sessionState mode="SQLServer" cookieless="false" timeout="5" allowCustomSqlDatabase="true" cookieName="My.Session"
sqlConnectionString="sanitized" />
<machineKey
validationKey="sanitized"
decryptionKey="sanitized"
validation="sanitized" decryption="sanitized" />
</system.web>
<system.webServer>
<handlers>
<clear />
<add name="MyHandler" path="*.bwsvc" verb="*" type="MySvc.MyServiceHandler, MySvc" />
</handlers>
</system.webServer>
</configuration>
I've read through The Web Server Could Not Find the Requested Resource and many other articles along the same lines. None of it seems applicable to this situation, nothing mentions handlers causing problems.
Am I missing something in my handler or is this something Visual Studio doesn't support or some other issue?
I found the problem. It turns out the <clear /> in the <handlers> section was responsible for causing the problem. As soon as that line is removed, the debugger works again (and many other things too).
Since my application pool is in integrated pipeline mode, the handlers section actually inherits from the server settings which specify what handles such core things as *.aspx and such, so doing a clear on it means that IIS didn't know what to do with anything in my application.

Running With DiagnosticMonitorTraceListener Outside of Azure Compute Emulator

We're using DiagnosticMonitorTraceListener as a general trace listener (primarily for for ASP.NET Health Monitoring) as well as an Enterprise Library 5 listener for exception handling. This works well when running on Azure but it's important that we be able to run the website outside of Azure with minimal changes.
One option is to register it dynamically as follows:
protected void Application_Start()
{
if (Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.IsAvailable)
{
System.Diagnostics.Trace.Listeners.Add(new Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener());
System.Diagnostics.Trace.AutoFlush = true;
}
}
This works for ASP.NET Health Monitoring and general uses of System.Diagnosics but not for Enterprise Library where we have the following hard-coded configuration:
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Event Log Listener" />
<add name="Azure Diagnostics Trace Listener" />
</listeners>
</add>
</categorySources>
Left unaddressed, calls to ExceptionPolicy.HandleException will generate:
Not running in a hosted service or the Development Fabric.
To conditionally remove this based on where the app is running, we could use the fluent configuration API for EL5 but would have to rewrite our configuration (it's all or nothing).
We could also use web.config transformations except that, in addition to having 3 different solution configurations already (e.g., dev, staging, production), we would have to introduce a 4th to differentiate between dev-standalone vs. dev-azure.
One last option would be to just create a custom listener that will either route all messages to ** ** (if running on Azure) or do nothing.
Any other suggestions?
FYI, ASP.NET Health Monitoring is configured as follows:
<healthMonitoring enabled="true">
<providers>
<add name="TraceWebProvider" type="System.Web.Management.TraceWebEventProvider" />
</providers>
<rules>
<add name="Application Events"
eventName="Application Lifetime Events"
provider="TraceWebProvider"
profile="Default"
minInstances="1"
maxLimit="Infinite"
minInterval="00:01:00" />
</rules>
</healthMonitoring>
You can create a DiagnosticMonitorTraceListener and then add it to the collection of TraceSources for your Category.
Remove Azure Diagnostics Trace Listener from EntLib configuration:
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Event Log Listener" />
</listeners>
</add>
</categorySources>
And then use the code below to add it at runtime:
protected void Application_Start()
{
if (Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.IsAvailable)
{
LogSource logSource;
Logger.Writer.TraceSources.TryGetValue("General", out logSource);
logSource.Listeners.Add(new Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener());
}
}

Resources