Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create single activity for rewrite rule #74

Merged
merged 3 commits into from
Jun 23, 2020

Conversation

rajkumar-rangaraj
Copy link
Collaborator

@rajkumar-rangaraj rajkumar-rangaraj commented Jun 4, 2020

Addressing Issue #73

Changes

(Please provide a brief description of the changes here.)

Modified EndRequest in TelemetryCorrelationHttpModule to skip activity creation for rewrite generated parent request.

Background Information

Initial version of the TelemetryCorrelationHttpModule had this activity creation within Application_Error and later moved to EndRequest.

https://github.com/aspnet/Microsoft.AspNet.TelemetryCorrelation/pull/1/files
https://github.com/aspnet/Microsoft.AspNet.TelemetryCorrelation/blob/cc1592d241fee1df40442790fddf7779c787e838/src/Microsoft.AspNet.Diagnostics/DiagnosticsHttpModule.cs

image

#2
https://github.com/aspnet/Microsoft.AspNet.TelemetryCorrelation/blob/c0c6b8ce9e3f371c6012a2646e4a5f253fcaea41/src/Microsoft.AspNet.Diagnostics/DiagnosticsHttpModule.cs

Notes from PR

image

@ghost
Copy link

ghost commented Jun 4, 2020

CLA assistant check
All CLA requirements met.

}
else
{
// Rewrite: In case of rewrite, a new request context is created, called the child request, and it goes through the entire IIS/ASP.NET integrated pipeline.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally somebody from asp.net team needs to comment on any other situation this may have happened. I can think of one off the top of my head - if there is another module registered before this module and it returned 401 or some actual content from the BeginRequest call. Than Begin will not be called for this module at all. And we will end up loosing the fact of this call.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifically for UrlRewrite, @TimothyMothra was working on logic that ensured that those will be parented to each other. This logic is somewhere in Application Insights http module. I wonder if this is a different case or the same

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SergeyKanzhelev, @TimothyMothra has worked on a change in application insights where parent and child request has same HttpContext. In this scenario, HttpContext generated at parent and child are different. I internally worked with IIS engineering team to check for the scenarios and came up with this change.

I will investigate the 401 error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Created new HttpModule and registered before TelemetryCorrelationHttpModule in pipeline
	  <modules>
		  <add name="One" type="WebApplication1.MyHttpModule1"/>
		  <add name="TelemetryCorrelationHttpModule" type="Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule, Microsoft.AspNet.TelemetryCorrelation" preCondition="managedHandler"/>
	  </modules>
  • Added below code to BeginRequest of custom module to respond with HTTP 401.
        private void Application_BeginRequest(object sender, EventArgs e)
        {
            var context = ((HttpApplication)sender).Context;
            context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
        }

Requested got executed in below order and Activity got created

  1. MyHttpModule1.BeginRequest
  2. TelemetryCorrelationHttpModule.BeginRequest
  3. MyHttpModule1.EndRequest
  4. TelemetryCorrelationHttpModule.EndRequest

Will check if we could get someone from ASP.NET team to review this one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to end the response after setting the status. Otherwise the module doesn't actually behave as authentication module as it continues an execution.

Copy link
Contributor

@SergeyKanzhelev SergeyKanzhelev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented

Copy link
Collaborator

@reyang reyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and it meets with the recommendation we've got from ASP.NET team.

Copy link
Collaborator

@reyang reyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants