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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:21:22+00:00 2026-05-28T00:21:22+00:00

my both serverName and serverPort lines are giving me error… When I take out

  • 0

my both serverName and serverPort lines are giving me error…
When I take out the servername assignment line, it gives me error in serverport assignment line.. the only common thing is the HttpContext.Current.Request…
what am I doing wrong? What can I do to work around the situation?

Code :

serverName = "localhost";
            if (serverName == null || serverName.Equals("localhost"))
                serverName = HttpContext.Current.Server.MachineName.ToLower();
            serverPort = Convert.ToInt32(HttpContext.Current.Request.ServerVariables["SERVER_PORT"]);
            baseUrl = "http://" + serverName;
            if (serverPort != 80)
                baseUrl += ":" + serverPort.ToString();

Here is the error it gives me when i try to debug it :

Request is not available in this context
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Request is not available in this context

Source Error:

Line 321:            // Old code left in for if this fails...
Line 322:
Line 323:            serverName = HttpContext.Current.Request.ServerVariables["SERVER_NAME"];
Line 324:            if (serverName == null || serverName.Equals("localhost"))
Line 325:                serverName = HttpContext.Current.Server.MachineName.ToLower();

//************* second source error when i remove serverName line ********/

Source Error:

Line 325:            if (serverName == null || serverName.Equals("localhost"))
Line 326:                serverName = HttpContext.Current.Server.MachineName.ToLower();
Line 327:            serverPort = Convert.ToInt32(HttpContext.Current.Request.ServerVariables["SERVER_PORT"]);
Line 328:            baseUrl = "http://" + serverName;
Line 329:            if (serverPort != 80)

//******************************************///

Source File: C:\CFG.cs    Line: 323

Stack Trace:

[HttpException (0x80004005): Request is not available in this context]
   System.Web.HttpContext.get_Request() +8806688
   labs.shared.config.CFGConstants.InitializeFromHttpContext() in C:\Users\...
   labs.shared.config.CFGConstants..ctor() in C:\Users\...
   labs.shared.config.CFGConstants.Get() in C:\Users\...
   labs.site.framework.FWStateHelper.OnApplicationStart(HttpApplication app) in C:\Users...
   labs.site.Global.Application_Start(Object sender, EventArgs e) in C:\Users\...

[HttpException (0x80004005): Request is not available in this context]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +2724290
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +128
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +188
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +295
   System.Web.HttpApplicationFactory.GetPipelineApplicationInstance(IntPtr appContext, HttpContext context) +56
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +231

[HttpException (0x80004005): Request is not available in this context]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8909915
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +85
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +333
  • 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-28T00:21:23+00:00Added an answer on May 28, 2026 at 12:21 am

    Where are you running this code? If it is in Application_Start, and you’re using IIS7’s Integrated pipeline, then you’ll run into this.

    Here’s a great article that does a much deeper dive. You’re options are:

    1. Don’t do this in Application_Start (recommended)
    2. Use the classic pipeline (not recommended).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Both the events are getting fired at the time onblur event. <%@ Page Language=C#
Both of these frameworks are great, but I've noticed that Knockout likes to point
Both Network.Socket.ByteString and Network.Socket.ByteString.Lazy have a send function. Network.Socket.ByteString has a sendTo function, but
Both events are fired by Netty framework , with a handle to the ChannelBuffer
Both Ruby and Python have the ability of calling the debugger from code (
Both methods MyBehavior::CreateSerializer() are not called of some reason, but ReplaceBehavior() method is working.
Both my Rails model and controller code need to write files to the file
Both are BDD (Behavior Driven Development) capable unit test frameworks for Scala written in
Both the interfaces seem to compare objects for equality, so what are the major
Both in Actionscript3 and Javascript these statements give the same result: /\S/.test(null) => true

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.