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 8027183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:44:17+00:00 2026-06-04T23:44:17+00:00

This is a Asp.net application (not MVC) running .Net 3.5 I did this: protected

  • 0

This is a Asp.net application (not MVC) running .Net 3.5

I did this:

 protected void Application_Start(object sender, EventArgs e)
 {

 ...

       builder.Register(c => new HttpContextWrapper(HttpContext.Current))
          .As<HttpContextBase>()
          .InstancePerHttpRequest();
 }

But it doesn’t work.

The error I am getting this:

No scope with a Tag matching ‘httpRequest’ is visible from the scope in which the instance was requested. This generally indicates that a component registered as per-HTTP request is being reqested by a SingleInstance() component (or a similar scenario.) Under the web integration always request dependencies from the DependencyResolver.Current or ILifetimeScopeProvider.RequestLifetime, never from the container itself.

So then I found this: https://stackoverflow.com/a/7821781/305469

And I did this instead:

       builder.Register(c => new HttpContextWrapper(HttpContext.Current))
          .As<HttpContextBase>()
          .InstancePerLifetimeScope();

But now when I do this:

public class HttpService : IHttpService
{
    private readonly HttpContextBase context;

    public HttpService(HttpContextBase context)
    {
        this.context = context;
    }

    public void ResponseRedirect(string url)
    {
        //Throws null ref exception
        context.Response.Redirect(url);
    }
}

and I got a Null Reference Exception.

Strangely, context.Response is not null, it is when I call .Redirect() that it throw.

I am wondering if using .InstancePerLifetimeScope(); is the problem.

BTW, I tried using Response.Redirect() and it works perfectly.

So what could be the problem?

Thanks,

Chi

  • 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-06-04T23:44:19+00:00Added an answer on June 4, 2026 at 11:44 pm

    It looks as though your HttpService class may be registered as a SingleInstance() (singleton) component. Or, one of the classes that has IHttpService as a dependency is a singleton.

    When this occurs, even though you’ve set up Autofac to return a new HttpContextBase instance per HTTP request (or lifetime scope, which is also correct) the HttpService class will hang on to whichever HttpContextBase was current when the single HttpService instance was created.

    To test this theory, try taking a dependency on HttpContextBase directly from a page, and see whether the problem still occurs. Figuring out which is the singleton component should be fairly straightforward if so.

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

Sidebar

Related Questions

This is not an MVC topic. I have an ASP.NET Application which performs URL
Disclaimer: this is not a question about how to install asp.net or an application
I am working on a hotel reservation module. This is an ASP.NET MVC application.
This is about asp.net mvc3 web application. We have used Object cache to store
I have an ASP.NET MVC web application running in IIS as a subweb; let's
This is driving me crazy. I written a simple ASP.NET MVC 1.0 application I
I have this web app that is running ASP .NET MVC 1.0 with LINQ
We are deploying our ASP.Net MVC application to a windows 2008 R2 server, running
I have an ASP.NET MVC 3 application running on both my local dev box
I'm developing an ASP.NET MVC application. Most of the controller actions are not supposed

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.