Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6725829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:51:13+00:00 2026-05-26T09:51:13+00:00

I am trying to debug a System.Web.HttpException that I keep getting. It could be

  • 0

I am trying to debug a System.Web.HttpException that I keep getting. It could be related to a BaiscAuthentication custom HttpModule I am trying to implement.

The BasicAuthentication HttpModule is subscribing to two events in the pipeline, BeginRequest and AuthenticateRequest.

All the code that subscribes to the BeginRequest event executes successfully. But before the code subscribing to AuthenticateRequest is executed I get a System.Web.HttpException.

The Exeception is as follows

Exception Details: System.Web.HttpException: This server variable cannot be modified during request execution.

and the stack trace is as follows

[HttpException (0x80004005): This server variable cannot be modified during request execution.]
System.Web.HttpServerVarsCollection.SetServerVariableManagedOnly(String name, String value) +2423129
System.Web.HttpServerVarsCollection.SynchronizeServerVariable(String name, String value) +28
System.Web.HttpRequest.SynchronizeServerVariable(String name, String value) +112
System.Web.Hosting.IIS7WorkerRequest.GetServerVarChanges(HttpContext ctx) +372
System.Web.Hosting.IIS7WorkerRequest.SynchronizeVariables(HttpContext context) +8743312
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +154

The code runs fine on my local machine but not on my host server.

UPDATE

I have found the offending code but not figured out how to fix the bug. Here is the basic code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;


namespace CustomHttpModule
{    
public class CustomModule : IHttpModule 
{
    public void Init(HttpApplication context)
    {
        context.BeginRequest += new EventHandler(context_BeginRequest);
        context.AuthenticateRequest += new EventHandler(context_AuthenticateRequest);
    }

    public void context_BeginRequest(Object sender, EventArgs e)
    {
        HttpApplication context = (HttpApplication)sender;
        string authHeader = context.Context.Request.Headers["Authorization"];

            if (String.IsNullOrEmpty(authHeader))
            {
                SendAuthHeader(context);
            }

        context.Context.Response.Clear();
        context.Context.Response.Write("Have reached the end of BeginRequest");
        //context.Context.Response.End();   
    }

    private void SendAuthHeader(HttpApplication context)
    {
        context.Response.Clear();
        context.Response.StatusCode = 401;
        context.Response.StatusDescription = "Authorization Request";
        context.Response.AddHeader("WWW-Authenticate", "Basic realm=\"Secure Area\"");
        context.Response.Write("401 baby, please authenticate");
        context.Response.End();
    }

    public void context_AuthenticateRequest(Object sender, EventArgs e)
    {
        HttpApplication context = (HttpApplication)sender;

        context.Context.Response.Clear();
        context.Context.Response.Write("Have reached the Beginning of AuthenticateRequest");
        context.Context.Response.End();
    }

    public void Dispose()
    {
    }
}
}

This code produces the error. But if you change the line..

string authHeader = context.Context.Request.Headers["Authorization"];

to

string authHeader = context.Context.Request.Headers["Host"];

then the code also executes fine.

It seemss to be accessing Headers["Authorization"]; that is causing the bug.

But if you leave Headers["Authorization"]; and uncomment the line //context.Context.Response.End(); then the code also executes fine.

The bug seems to happen between the end of BeginRequest and the start of AuthenticateRequest. But seems to be related to the code Headers["Authorization"];

I have no idea why this should be. I am wondering if it is just a bug with the server as the code runs fine on my local machine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:51:14+00:00Added an answer on May 26, 2026 at 9:51 am

    It looks as though the bug is caused by the server variable AUTH_USERbeing changed which is not allowed by the integrated pipeline in iis7 and above.

    http://support.microsoft.com/kb/2605401/en-us?sd=rss&spid=14855

    This link gives details.

    It says authentication notifications can be handled within a managed module. However I still don’t know how to acheive this. But I am going to open a new question on that topic as this question is getting rather lengthy and is effectively solved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web.config file that's transformed using a web.debug.config file. Trying to get
I am trying to debug a strange issue with users that have LogMeIn installed.
I am trying to debug an ActiveResource call that is not working. What's the
I'm trying to add functionality to a simple web service that will allow me
I'm trying to use APPCMD to set debug=false in web.config , per the documentation
I am trying to pull a value from my Web.Debug.Config file most specifically from
I am having a rather bizarre error when trying to debug a .NET web
Trying to debug an issue with a server and my only log file is
When trying to debug a program on Windows I can't seem to find where
I'm currently trying to debug a customer's issue with an FTP upload feature in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.