debugging a HTTP Handler - c#

I am using IIS 6 on 2003. I have created a HTTP handler dll that inherits from IHttpAsyncHandler. The dll builds into the inetpub\www8080root\common\bin directory. It is meant to intercept all requests.
The web site is set to monitor port 8080. I have created a common folder in the www8080root directory and have created a virtual directory in II6 to point to it.
I created a web.config file in the common directory
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" defaultLanguage="c#" />
<httpHandlers>
<add verb="*" path="*"
type="x2Handler.x2Handler, x2Handler" />
</httpHandlers>
</system.web>
</configuration>
When I access http://localhost:8080/common/index.html the HTTP handler causes a crash of w3wp.exe, when I look in the event logs I can see the error within the handler that caused the crash. When I set a breakpoint within VS 2005 the code it doesn't get hit.
In order to debug I need to somehow attach to the process when it is running under IIS but as soon as it processes a request, it crashes.
How do I debug a HTTP Handler dll under IIS? I can't see a aspnet_wp.exe process to attach to as described here: C#, Debugging an HTTPHandler
EDIT:
By adding Debugger.Break() I now receive the message "w3wp.exe has triggered a breakpoint" and it allows me to select a debug environment, but it loads without symbols
No symbols are loaded for any call stack frame. The source code cannot be displayed.
I set Tools->Options->Debugging->Enable Just My Code
I set the path to the common/bin location to load symbols from. Any manually set breakpoints still display:
The breakpoint will not currently be hit. No symbols have been loaded for this document.
EDIT:
When it loads it appears to be looking for the symbols of ntdll.pdb. Even if I manually load the symbol file for the httpHandler it makes no difference.
The code is definitely executing though.

Add Debugger.Break() a few lines before the exception occurs. This should give you a popup asking to attach a debugger.

The problem was that .Net had been installed prior to the version IIS. I had noticed the "Edit configuration" button was disabled and found this site http://www.warfiblog.com/edit-configuration-disabled.
Following the instructions:
You will need to go to Start -> Microsoft Visual Studio 2005 -> Visual Studio Tools -> Visual Studio 2005 Command Prompt. On the prompt write down this command:
aspnet_regiis -r
The above command will register dot net with IIS and now the button will also be enabled.
In doing that it fixed the debugging issue!

Related

"Crypto settings changed" message shown when launching an Azure Cloud Service locally

I’m getting the following behavior when I try to launch an Azure Cloud Service locally
1) Popup that the debugging environment is getting ready is shown (step1.jpg)
2) Message “Your about to be signed out, crypto settings changed” is shown (step2.jpg)
3) Force restart of the notebook is performed (step3.jpg)
This is happening constantly in both debug and start without debugging options.
I tried changing the properties of the azure cloud service but it didn’t help. I also tried to use the internet what does this message mean and could not find any relevant data. appreciate ANY help. Thanks!
Check you ServiceDefinition.csdef for startup tasks. I think you maybe running the DisableSslv3.cmd script on your local machine causing it to force a restart. Just comment out the line while debugging locally.
In addition to the answer of #user2282308, I would say that in a more global approach, it worth to check the startup tasks in the serviceDefinition.csdef and verify that all tasks are executed as "expected".
#user22822308 spoke about DisableSslv3.cmd, but on my side, the issue was that the script runTLSsettings.cmd should be executed only when running on Azure service (this script ends with a reboot of the machine and the famous "crypto settings changed")
This is the serviceDefinition.csdef integration that is proposed by Microsoft for the runTLSSettings script:
<Startup>
<Task executionContext="elevated" taskType="simple" commandLine="RunTLSSettings.cmd">
</Task>
</Startup>
This is ok when debugging your cloud service in Visual Studio 2019, but as soon as you try to debug with Visual Studio 2022 you will receive the "Crypto settings changed".
My feeling is that the startup task is not done in VS 2019 meanwhile it is done in VS 2022.
Thus, what is missing is the definition of the environment variable that indicate to runTLSSettings script if we are running on emulator or not.
The environment variable definition is well explained in this other microsoft documentation:
https://learn.microsoft.com/en-us/azure/cloud-services/cloud-services-startup-tasks#environment-variables
At the end, this is the correct csdef:
<Startup>
<Task commandLine="runTLSSettings.cmd" executionContext="limited" taskType="simple">
<Environment>
<Variable name="ComputeEmulatorRunning">
<RoleInstanceValue xpath="/RoleEnvironment/Deployment/#emulated" />
</Variable>
</Environment>
</Task>
This happens every single time I run Visual Studio without elevated privilege's. When I start debugging the cloud service and the azure emulator starts, I get this message and the computer reboots.

C# MVC: Cannot Debug in IIS Express

I just changed my laptop. I am moving my old project done in MVC 4 and was done in Visual Studio 2012. My current Visual Studio in my new laptop is 2017 version.
There is a problem when I want to debug my MVC application. This error comes out after I run the debug:
HTTP Error 403.14 - Forbidden The Web server is configured to not list
the contents of this directory.
Most likely causes: A default document is not configured for the
requested URL, and directory browsing is not enabled on the server.
I never set my application to be listed in directory browser. My application is an MVC application which will run global.asax and redirect to my home page.
How can I fix this?
enable directory browsing.
keep this into your web config file then rename the add value="pagename.aspx"
<system.webServer>
<defaultDocument>
<files>
<add value="yourpage.aspx" />
</files>
</defaultDocument>
<directoryBrowse enabled="false" />
</system.webServer>
or
<system.webServer>
<directoryBrowse enabled="true" />
</system.webServer>
You can also enable directory browsing from IIS
Open a command prompt, and then go to the IIS Express folder on your computer. For example, go to the following folder in a command prompt: C:\Program Files\IIS Express
Type the following command, and then press Enter:
appcmd set config /section:system.webServer/directoryBrowse /enabled:true
Got the same error, but MVC5 on VS2017. Eventually found I got the error because i had marked Application_Start() in Global.asax as a static. I did that because i made the mistake of following this Code Analysis recommendation:
This is a potential duplicate of
HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents
Different context since you are trying to debug in IIS express and you are not hosting the application in IIS, however the error is the same and the answers is worth checking out. Could set you on the right path.
Would have commented but don't have enough rep yet.
Make sure you have defined your default application inside the hosts file in your new laptop.
This is a cause for many headache.
See it under:
C:/Windows/System32/Drivers/etc/hosts

ASP.NET project not building in my Testing machine

I have a running project that I need to modify. I am trying to load the whole project into my Visual Studio 15 CE for modifying. I have got the whole list of files in my Solution explorer and then also the database in SQL manager. When I click execute, it gives an error list! Here is the image. enter image description here
Then In the Browser, I get this message:
HTTP Error 500.24 - Internal Server Error
An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.
Most likely causes:
system.web/identity#impersonate is set to true.
Things you can try:
If the application supports it, disable client impersonation.
If you are certain that it is OK to ignore this error, it can be disabled by setting system.webServer/validation#validateIntegratedModeConfiguration to false.
Detailed Error Information:
Module ConfigurationValidationModule
Notification BeginRequest
Handler StaticFile
Error Code 0x80070032
Requested URL http://localhost:55014 /fanKc9TuE6zuHQVMTPwHWVIHJCM.html
Physical Path H:\Quoting system files\MGF_LIVE_BACKUP\fanKc9TuE6zuHQVMTPwHWVIHJCM.html
Logon Method Not yet determined
Logon User Not yet determined
Request Tracing Directory D:\Old folders\Documents\IISExpress \TraceLogFiles\MGF_LIVE_BACKUP
This is an application Pool setting issue..
Try going into IIS and changing the app pool for your application to use classic mode instead of integreted mode.
Alternatively you can add this to your Web.Config:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>

How can i remove URLmapping when i already public to IIS

In my web.config, I setting like below because i want redirect to ~/layout/asp
<urlMappings enabled="true">
<add mappedUrl="~/layout/asp" url="~/"/>
</urlMappings>
But later, i don't want redirect anymore, i was delete above code in web.config and public to IIS but it still redirect to layout/asp
I think IIS is save my setting
It working correct when i run on debug environment in visual studio
Restart your IIS: iisreset /restart

Parse error with Generic Handler using IIS

What made me curious is that the generic handler works just fine when I'm running the Web App in a Visual Studio ASP.NET Development Server. When I change the config to run it directly from IIS the handler just dies.
It's an image handler, it writes back an array of bytes to be rendered in an Image object. As I said, it works fine in VS Development Server, but fails on IIS. It doesn't even get called...
The error I get when I'm trying to call it directly is this:
Parser Error Description: An error occurred during the parsing of a
resource required to service this request. Please review the following
specific parse error details and modify your source file
appropriately. Parser Error Message: Could not create type
'YourImageHandler'. Source Error: Line 1: <%# WebHandler
Language="C#" CodeBehind="YourImagehandler.ashx.cs"
Class="YourImageHandler" %>
Handler on web.config:
<system.web>
<httpHandlers>
<add verb="*" path="*.ashx" type="YourImageHandler"/>
</httpHandlers>
</system.web>
The Generic Handler is in the same assembly of the Web Project, and the whole thing is running on IIS 7.
If you are using IIS 7 in pipeline mode then the handler definition must be in <System.webServer>
Like this:
<system.webServer>
<handlers>
<add name="YourImageHandlerName" path="*.ashx" verb="*" type="YourImageHandler" />
</handlers>
</system.webServer>
Check here: http://blogs.msdn.com/b/tmarq/archive/2007/08/30/iis-7-0-asp-net-pipelines-modules-handlers-and-preconditions.aspx
IIS 7.0 has two pipeline modes: integrated and classic. The latter is
sometimes referred to as ISAPI mode.
Integrated mode allows both managed and native modules to register for
events in the IIS pipeline. This enables many new scenarios, such as
applying ASP.NET forms authentication to non-asp.net requests (static
files, classic ASP files, etc).
Classic mode is identical to IIS 6.0. In classic mode, the ASP.NET
pipeline (BeginRequest, AuthenticateRequest,…, EndRequest) runs
entirely within the IIS pipeline’s EXECUTE_REQUEST_HANDLER event.
Think of ASP.NET in classic mode as a pipeline within a pipeline.
The other option is to run your site in "classic" mode, in classic mode IIS 7 works like IIS 6 and has the same behaviour (for what matters here) as your Cassini web server.
Hope that help.
You have to add preCondition attribute in web.config file
<add name="HandlerName" verb="*" path="Handlers/HandlerName.ashx" type="Namespace/HandlerClassName, MyAssembly, Version=1.0.*, Culture=neutral" preCondition="classicMode,runtimeVersionv4.6.1"/>
Its working for my error now.
I think you should add a managed handler mapping to IIS. it is not enough to add config. You can look here .

Categories

Resources