locked
System.Web.HttpException: Request is not available in this context RRS feed

  • Question

  • User751963951 posted

    I am testing a site on a hosted server, The connection strings and files are all located and configured according to typical standards.

    My problem is explained below only I have no clue what it means or how to correct the issue. Can anyone help [:D]

    The Test Site is the Classifieds Starter Kit with a few to many mods. 

     

    Server Error in '/' Application.

    --------------------------------------------------------------------------------

    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:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

     

    [HttpException (0x80004005): Request is not available in this context]

    System.Web.HttpContext.get_Request() +3465893

    AspNet.StarterKits.Classifieds.Web.TestSiteHttpApplication.GetSiteUrl() +29

    AspNet.StarterKits.Classifieds.Web.TestSiteHttpApplication.Application_Start(Object sender, EventArgs e) +12

    ASP.global_asax.Application_Start(Object sender, EventArgs e) +133

    [HttpException (0x80004005): Request is not available in this context]

    System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +3385130

    System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +125

    System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +182

    System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +259

    System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +245

    [HttpException (0x80004005): Request is not available in this context]

    System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +3465475

    System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +69

    System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +675

     

     

    --------------------------------------------------------------------------------

    Version Information: Microsoft .NET Framework Version:2.0.50727.1434; ASP.NET Version:2.0.50727.1434

    Tuesday, July 1, 2008 10:23 PM

Answers

All replies

  • User187056398 posted

    In the Application_Start event, a call is being made to GetSiteUrl which is trying to access the Request object.

    The Request object probably doesn't exist yet becase the application is just starting and not processing Requests.

    You may need to post the code from your Application_Start event.

    [HttpException (0x80004005): Request is not available in this context]

    System.Web.HttpContext.get_Request() +3465893

    AspNet.StarterKits.Classifieds.Web.TestSiteHttpApplication.GetSiteUrl() +29

    AspNet.StarterKits.Classifieds.Web.TestSiteHttpApplication.Application_Start(Object sender, EventArgs e) +12

    ASP.global_asax.Application_Start(Object sender, EventArgs e) +133

    Tuesday, July 1, 2008 11:42 PM
  • User751963951 posted

    Well That makes alot of sense [:D]

    Wouldnt have a clue what to do about that though.

    Hope this can help you to help me. Thanks for your response.

     

    =========

    Global.ascx

    =========

    void Application_Start(object sender, EventArgs e)

    {

    // Code that runs on application startup

    Application["activeuser"] = 0;

    if (!Roles.RoleExists("Administrators")) Roles.CreateRole("Administrators");

    if (!Roles.RoleExists("Guests")) Roles.CreateRole("Guests");TestSiteHttpApplication cha = new TestSiteHttpApplication();

    cha.Application_Start(sender, e);

    }

     ======================================

    public class TestSiteHttpApplication : HttpApplication

    ================== ====================

    private string GetSiteUrl()

    {

    string baseUrl = null;

    HttpContext c = HttpContext.Current;

    if (c != null)

    {

    string port = c.Request.ServerVariables["SERVER_PORT"];

    if (port == null || port.Equals("80") || port.Equals("443"))

    port = String.Empty;

    else

    port = ":" + port;

    string protocol = c.Request.ServerVariables["SERVER_PORT_SECURE"];

    if (protocol == null || protocol.Equals("0"))

    protocol = "http://";

    else

    protocol = "https://";
    baseUrl = protocol + c.Request.ServerVariables["SERVER_NAME"] + port + c.Request.ApplicationPath;

    }

    return baseUrl;

    }

    Wednesday, July 2, 2008 12:00 AM
  • User-225114762 posted
    TestSiteHttpApplication cha = new TestSiteHttpApplication();

    cha.Application_Start(sender, e);

    Apparently you call GetSiteUrl() from the Application_Start() method of TestSiteHttpApplication.

    You can't do that, since GetSiteUrl() attempts to use the Request property of HttpContext.Current - there is no Request available at that time.

    If this code is written by you, you'll have to rethink the strategy. If this code is part of the starter kit, it's likely to do with something changing in IIS 7, since it probably has worked before.

    Either way - you can't refer to HttpContext.Current.Request in your Application_Start as is seen. You'll have to do whatever you do at a later stage.

    Wednesday, July 2, 2008 1:42 AM
  • User751963951 posted

    Apparently you call GetSiteUrl() from the Application_Start() method of TestSiteHttpApplication.

    You can't do that, since GetSiteUrl() attempts to use the Request property of HttpContext.Current - there is no Request available at that time.

    If this code is written by you, you'll have to rethink the strategy. If this code is part of the starter kit, it's likely to do with something changing in IIS 7, since it probably has worked before.

    Either way - you can't refer to HttpContext.Current.Request in your Application_Start as is seen. You'll have to do whatever you do at a later stage.

     

    Well thats a dissapointment. Yes it is a difference between IIS6 and IIS7. Have tested on 6 earlier and todays test was on 7.

    That piece of code is standard in the kit. Hope someone can help me sort this out as the whole site seems to rely on this one little piece of code.

     

    Thanks Alot for your reply [:D]

     

    Wednesday, July 2, 2008 2:05 AM
  • User-225114762 posted

    That piece of code is standard in the kit.

    It would then appear that this forum is the appropriate one. You sent a note about the question being moved here, but we'll let it stay here then.

    Wednesday, July 2, 2008 2:47 AM
  • User751963951 posted

    That piece of code is standard in the kit.

    It would then appear that this forum is the appropriate one. You sent a note about the question being moved here, but we'll let it stay here then.

    Yeah it can stay here, Would of thought it had been better in something like Installation and Setup or stayed in the Getting Started  as its still not specific to the starter kit and im most likely not the only one thats gonnna strike this problem as its an error in result to the Request() being made.

    I have been trying to find more infromation on the HttpContext.Current.Request problem in my application start and why it wont work in IIS7 but there just dose not seem to be anything available.

     Any leads to point me in the right direction are welcome [:D]

     

    Thanks to those that have helped so far..

     

     

    Wednesday, July 2, 2008 3:25 AM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 2, 2008 3:41 AM
  • User-225114762 posted

    LEGEND

    ?

    Wednesday, July 2, 2008 3:58 AM
  • User751963951 posted

    LEGEND

    ?

     

    Sorry, Yeah Your a legend. Have been searching non stop with no leads. Quickly changed my code after reading through your link and recompilled my site and away it goes [:D] They need to include that blog on the IIS help site and in MSDN etc. that is where I was looking.

     

    Im so glad. Thank you so much.

     

    Wednesday, July 2, 2008 4:19 AM
  • User-225114762 posted

    Thank you so much

    [:$] You're welcome!

    Wednesday, July 2, 2008 4:26 AM
  • User1312457015 posted

    Can I ask what you changed your code to?  Your code is identical to mine, which is part of the ASP.NET Classified Ads starter kit.  I'm not following the blog apparently.  Is there any way to find out what specifically you changed in the code snippet you posted above?   This must be a problem for a LOT of people right now.  Thanks!!! 

    Friday, July 25, 2008 7:07 PM
  • User751963951 posted

    Can I ask what you changed your code to?  Your code is identical to mine, which is part of the ASP.NET Classified Ads starter kit.  I'm not following the blog apparently.  Is there any way to find out what specifically you changed in the code snippet you posted above?   This must be a problem for a LOT of people right now.  Thanks!!! 

     

    My code has been modified for over a year now so I doubt it can be identical to yours [:P]

    There were a few modifications made to my code and I will post a blog on this in the next few days of all my modified code in C#

    Svante gave me the head start on what the problem was how ever fixing the problems for the application to run in the new IIS7 was interesting and required further research.

    I will post a link here as soon as my blog is completed.

    Regards [:D] 

    Friday, July 25, 2008 7:24 PM
  • User1312457015 posted

     Are we talking about the same thing?  According to the post at the top, you were having this issue a few weeks ago?  Sorry if I'm missing something. 

    Here is my error:

     

    Line 84:                if (c != null)
    Line 85: {
    Line 86: string port = c.Request.ServerVariables["SERVER_PORT"];
    Line 87: if (port == null || port.Equals("80") || port.Equals("443"))
    Line 88: port = String.Empty;

     

    I'm surprised this forum isn't full of people with this issue?  Seems it impacts every single user who is on IIS 7?? 

    Friday, July 25, 2008 7:48 PM
  • User751963951 posted

     Are we talking about the same thing?  According to the post at the top, you were having this issue a few weeks ago?  Sorry if I'm missing something. 

    Here is my error:

     

    Line 84:                if (c != null)
    Line 85: {
    Line 86: string port = c.Request.ServerVariables["SERVER_PORT"];
    Line 87: if (port == null || port.Equals("80") || port.Equals("443"))
    Line 88: port = String.Empty;

     

    I'm surprised this forum isn't full of people with this issue?  Seems it impacts every single user who is on IIS 7?? 

     

     

    Yes this is very much the same issue.. I am currently working on the Blog with the fix for you and many others. Most hosting companys have yet to supply IIS7, those that have all ready launched there sites on IIS6 wont be having any trouble and probably have yet to upgrade to IIS7, so expect more posts to this forum very shortly..

    Regards 

    Friday, July 25, 2008 9:33 PM
  • User751963951 posted

    The fix is now available on my blog

    >>Asp.Net Classifieds Starter Kit Does Not Run in IIS7<<

    Any questions feel free to ask [:D] 

     

    Saturday, July 26, 2008 4:39 AM
  • User1484644233 posted

    what happened to your blog? Page is not there anymore?

    Saturday, September 13, 2008 11:51 AM
  • User751963951 posted

     

    what happened to your blog? Page is not there anymore?

    Sorry about that. Updates have broken a few links with the new Url Re-Writer's. Have updated the links and have also posted below.

    >>Asp.Net Classifieds Starter Kit Does Not Run in IIS7<<

    Any questions feel free to ask [:D]

     

    Sunday, September 21, 2008 12:29 AM
  • User1055515993 posted

     The link to SpiderMaster's blog where he documented this fix is missing. I am having this same issue. Can someone post on here what the fix was please.

    Thanks

    Monday, May 4, 2009 7:55 PM
  • User-122480877 posted

     The link to SpiderMaster's blog where he documented this fix is missing. I am having this same issue. Can someone post on here what the fix was please.

    Thanks

    Instead of messing up someones thread you should ask thema personal message.He has been online recently

    http://weblogs.asp.net/reganschroder/ The fix is documented here

    Monday, May 4, 2009 9:47 PM
  • User1055515993 posted

     No one is messing up anyones thread. The question I asked is worthy of a forum post cause anyone who reads it will benefit from it cause the link is dead. Now that you posted a valid link to the solution, someone else doesnt need to bug the OP with PM's asking for the actual link.

     On another note, Thanks for the link. Im sure anyone else who stumbles onto this post will be Thankful to you as well.

     

    Monday, May 4, 2009 10:54 PM