We help IT Professionals succeed at work.

HTTP Context.Current No Longer Works after upgrading to Windows 10/IIS 10

High Priority
387 Views
Last Modified: 2018-12-10
After upgrading to Windows 10, my local Development Copy of the code using my local IIS Express Version 10 is unable to get the current HttpContext.  The same code
works on our Development and Live Server that are running IIS 8.5.    I need help updating the code since it appears I can't use HttpContext.Current anymore.  

/// <summary>
        /// Returns the URL for this link
        /// </summary> 
        [NotMapped]
        public string trueUrl
        {
            get
            {
                if (url != null)
                    return url;

                if (HttpContext.Current != null)
                {
                    var urlhelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
                    return urlhelper.Action(action, controller, new { area = area });
                }

                return "ERROR";
            }
        }

Open in new window

Error.PNG
Comment
Watch Question

Dustin SaundersCo-Founder and Chief Architect
CERTIFIED EXPERT
Top Expert 2016

Commented:
What sort of authentication settings are you using?  Is anonymous auth enabled?
Crystal RouseTask Lead

Author

Commented:
I'm running this on my local machine using Visual Studio's IIS. How do I check this setting?
Dustin SaundersCo-Founder and Chief Architect
CERTIFIED EXPERT
Top Expert 2016

Commented:
You should be able to see those settings in the web.config
Crystal RouseTask Lead

Author

Commented:
I've searched thru my web.config file and can't find anything where anonymous is enabled.
Dustin SaundersCo-Founder and Chief Architect
CERTIFIED EXPERT
Top Expert 2016

Commented:
What about the authentication settings in general?  Winforms?
Crystal RouseTask Lead

Author

Commented:
We also had our Team Foundation Server moved to a new server and I'm wondering if when we synced our code, a setting was maybe changed?  

I don't see anything regarding WinForms.  I searched for Auth and found the following. I'm not really sure what section of the web config file deals with security settings.

 <sectionGroup name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection, DotNetOpenAuth.Core">
      <section name="messaging" type="DotNetOpenAuth.Configuration.MessagingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" />
      <section name="reporting" type="DotNetOpenAuth.Configuration.ReportingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" />
      <section name="openid" type="DotNetOpenAuth.Configuration.OpenIdElement, DotNetOpenAuth.OpenId" requirePermission="false" allowLocation="true" />
      <section name="oauth" type="DotNetOpenAuth.Configuration.OAuthElement, DotNetOpenAuth.OAuth" requirePermission="false" allowLocation="true" />
    </sectionGroup>
Co-Founder and Chief Architect
CERTIFIED EXPERT
Top Expert 2016
Commented:
I would be surprised I suppose if the repo change was part of the problem.  Did anything else change on the domain?  Did anyone else upgrade to Win10 and have the same issue?
Crystal RouseTask Lead

Author

Commented:
Just me and the other developer on my Team.  When running locally the code does not work.  When running on our Development server it does work.  I'm really stumped.  We use HttpContext throughout the site, it works everywhere else except this instance.  I'll write up the workflow and update tomorrow.
Crystal RouseTask Lead

Author

Commented:
We are using REACT.  The Home Page (Index) uses a React Layout.cshtml.  The React Layout contains in the body tag:    @RenderBody()

Using MVC, in Models:

The HomeHub.cs contains the following class:

public void Init(JObject data)
            {
                CodeFirstDB db = new CodeFirstDB();
                hub.Clients.Caller.HomepageData(db.homepageLinks.ToList());
            }

The HomeLink.cs contains properties for the HomeLink table as well as the public string trueUrl.  

In Content>Application:

We have a Homepage folder that contains the Homepage.jsx

I can provide more info it would help. Just trying to provide some basic info of how it works.
Crystal RouseTask Lead

Author

Commented:
Closing this question