new handler triggers debug failure in visual studio - asp.net

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.

Related

IIS 10 ServiceStack .Net4.8 404

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.

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

How to write to OutputDebugString from ASP.net web-site?

i need to output some debugging information from code on a web-site.
How can i call OutputDebugString from an ASP.net web-site, and have it appear to users running DbgView?
Note: Web-sites do not support System.Diagnostics.Trace.TraceWarning(...).
Okay, here is a complete example. It's a console but the principles and the code are much the same. I couldn't test capturing from OutputDebugString on my machine today because I don't have admin rights. On a server, you'd write to TextWriterTraceListener instead of a console. If you can't write and read from OutputDebugString using pinvoke, may the customer doesn't have the rights or the app doesn't have the necessary rights.
Also! If the Debug.WriteLine isn't showing up, maybe the website is compiled in RELEASE mode and DEBUG isn't define. TRACE by default is defined for RELEASE And DEBUG. TraceSource writes to OutputDebugString unless you've cleared the default listener, which a lot of people do as a matter of habit since OutputDebugString in my experience can slow things down esp if you aren't actually looking at the output at the moment.
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace TraceToOutputDebugString
{
class Program
{
[DllImport("kernel32.dll")]
static extern void OutputDebugString(string lpOutputString);
static void Main(string[] args)
{
//Put these lines in your asp.net Page
OutputDebugString("Hello from Pinvoke OutputDebugString");
TraceSource trace = new TraceSource("app");
trace.TraceInformation("Hello from TraceSource");
Trace.TraceInformation("Hello from 1.1 Trace.TraceInformation");
Debug.WriteLine("Hello Debug.WriteLine");
System.Console.ReadKey();
}
}
}
And here is the config.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<sources>
<source name="app" switchName="app">
<listeners>
<add name="Console" type="System.Diagnostics.ConsoleTraceListener"/>
</listeners>
</source>
</sources>
<switches>
<add name="app" value="Information"/>
</switches>
<trace>
<listeners>
<add name="Console" type="System.Diagnostics.ConsoleTraceListener"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>

Site deployed, asp pages work fine, but not my handlers

I have deployed a website using Visual Studio 2010 on IIS6. I used one of the four methods available : the basic file copy. It's like ordering to build to a different location, rather than the usual debug/release path in the project folder.
Anyway, the site that I released is responsive. As I have given all authorizations possible, I can browse contents, get files, most importantly execute asp/aspx pages.
I have declared the following http handler, it answers to URL/[anytext].text in debug mode (i.e. http://localhost/blablabla.text) and sends back an empty XML at the moment.
The same thing doesn't work after I deploy.
Code of my handler :
namespace WebApplication3
{
public class HttpHandler : IHttpHandler
{
public void ProcessRequest(System.Web.HttpContext context)
{
HttpResponse objResponse = context.Response;
objResponse.ContentType = "text/plain";
objResponse.Write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
objResponse.Write("</xml>");
}
public bool IsReusable
{
get
{
return true;
}
}
}
}
web.config that gets deployed at the root of my IIS virtual directory :
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation targetFramework="4.0" />
<httpHandlers>
<add verb="*" path="*.text" type="WebApplication3.HttpHandler, WebApplication3"/>
</httpHandlers>
</system.web>
</configuration>
And just if that can help, this is the web.config that I have in my VS2010 solution :
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpHandlers>
<add verb="*" path="*.text" type="WebApplication3.HttpHandler, WebApplication3"/>
</httpHandlers>
</system.web>
</configuration>
Why would that not work as well right after the release ? I guess there's something missing. Most likely the web.config is never read ?
I finally found what this was about. The deployment process I described is fine. What you need to know, is that you need to tweak your IIS settings depending on what kind of handler your are adding.
In my case, I needed to add an extension (.text) in IIS.
http://msdn.microsoft.com/en-us/library/bb515343.aspx

VirtualPathProvider doesn't (quite) work in production on IIS 7.5

I have been working on a project that has common bits of functionality, specifically I wanted to share the master file and related images/js/etc. To that end, the master page and its dependent files are all wrapped into a "global" DLL that is utilized by all "subprojects". This all worked great in development, but deployment yielded a surprise which seems to catch a lot of people off guard: VirtualPathProvider doesn't work when precompiled.
Now thanks to this blog post containing a workaround I was able to give another attempt at getting it to work. Regretfully, it still doesn't.
I opted to get rid of my Global.asax implementation and went with the blog post's AppInitialize approach:
public static class AppStart
{
public static void AppInitialize()
{
HostingEnvironment hostingEnvironmentInstance = (HostingEnvironment)typeof(HostingEnvironment).InvokeMember("_theHostingEnvironment", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField, null, null, null);
MethodInfo mi = typeof(HostingEnvironment).GetMethod("RegisterVirtualPathProviderInternal", BindingFlags.NonPublic | BindingFlags.Static);
mi.Invoke(hostingEnvironmentInstance, new object[] { new MasterPageProvider() });
}
}
Since the actual provider works in debug, I won't include it. If you would like to see it, don't hesitate to ask. Just wanted to keep the question as short as possible.
The interesting aspect to this whole situation is that production yields no errors about not being able to find the master page. To me, this means the provider is working, but for whatever reason the rest of the resources (js/css/etc) aren't being retrieved from the assembly properly.
So my question comes down to this: what are the reasons that this solution would work great in development, but not in production on IIS 7.5?
UPDATE 11/20/2011
Tried out David Ebbo's suggestion and had no results unfortunately. My web config looks something like this now:
<configuration>
<connectionStrings>
<clear />
<!-- ... -->
</connectionStrings>
<system.web>
<pages>
<controls>
<!-- ... -->
</controls>
</pages>
<compilation debug="true" targetFramework="4.0" />
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
UPDATE 11/21/2011
Just to verify my suspicion that the VirtualPathProvider was actually working, I commented out the third line (mi.Invoke(....) and redeployed the site. As I suspected, it now breaks due to not being able to find the MasterPage file. This issue appears to be related to only static files being delivered through the VPP.
IIS 7.5 will handle the static files itself. You need to put a line for each static file you want it to ignore in your web.config file to make them get routed through your VPP. See below for examples.
<system.webServer>
<handlers>
<add name="Images" path="*.png" verb="GET,HEAD,POST" type="System.Web.StaticFileHandler" modules="ManagedPipelineHandler" resourceType="Unspecified" />
<add name="Stylesheets" path="*.css" verb="GET,HEAD,POST" type="System.Web.StaticFileHandler" modules="ManagedPipelineHandler" resourceType="Unspecified" />
</handlers>
</system.webServer>
Maybe the problem is that requests for static files are not going through ASP.NET by default in IIS.
Try whether turning on runAllManagedModulesForAllRequests in web.config helps. e.g.
<modules runAllManagedModulesForAllRequests="true" />
Take a look at this post. It explains how to get static files through a virtual path provider in IIS 7. I believe this will solve your problem.

Resources