I need my web app to target the .net framework 4.6 so web services use tls 1.2 by default

jackbenson
jackbenson used Ask the Experts™
on
I need my .net web application to target the .net framework 4.6 so web services use tls1.2 by default

I did not write the initial application but have taken over its maintenance for the past few years.

in the web.config there is the following code

<system.web>
      <compilation debug="true">
      <assemblies>
        <add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Data.Services.Client, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Data.Services.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
      </assemblies>
    </compilation>
  </system.web>

Open in new window


I am not sure why this is there and the following code is commented out:

  <!--
  <system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  -->

Open in new window


can anyone explain it to me
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

Commented:
I am not sure who or why the compilation and runtime tags are commented but if you want to target framework 4.6 you can change it in the comments.

Also are these the correct web.config? Maybe in Release/Prod different set of web.config is being deployed.
jackbensonDirector

Author

Commented:
So you can have the code "add assembly="System, Version=4.0.0.0" as well as targeting 4.6 uncommitted?
Chief Technology Ninja
Distinguished Expert 2018
Commented:
Yes. Please Refer to: https://blogs.msdn.microsoft.com/webdev/2012/11/19/all-about-httpruntime-targetframework/

<httpRuntime targetFramework="4.5" />
The effect of this attribute is twofold. First, it controls the CLR’s quirks mode behavior, just like the <supportedRuntime> element does in a console application.

Second, <httpRuntime targetFramework="4.5" /> is a shortcut that allows the ASP.NET runtime to infer a wide array of configuration settings. If the runtime sees this setting, it will expand it out just as if you had written the following:

<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="WebForms" />
  </appSettings>
    <system.web>
      <compilation targetFramework="4.5" />
      <machineKey compatibilityMode="Framework45" />
      <pages controlRenderingCompatibilityVersion="4.5" />
    </system.web>
</configuration>

Open in new window

CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

jackbensonDirector

Author

Commented:
you never answered this question:

So you can have the code "add assembly="System, Version=4.0.0.0" as well as targetFramework="4.6" uncommitted?
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

Commented:
I think I started my last answer posted on 1st June 2018, with Yes and it was the only question you asked. So that Yes was the answer to your question.
jackbensonDirector

Author

Commented:
Thank you. I added the targetFramework="4.6" and now it is using tls1.2 by default.

Can i delete the references like:
 "add assembly="System, Version=4.0.0.0"

Or could they still be needed?
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

Commented:
They might be needed. As I explained in earlier answer, 4.6 targetFramework is the instruction for ASP.Net to infer the settings... while Add Assembly references is used to explicitly refer to an assembly. So if your code depends on it, you will start getting errors.
jackbensonDirector

Author

Commented:
Thanks

Would the error happen at compilation or runtime? Compilation is easier to fix obviously
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

Commented:
I believe it will be at runtime.
jackbensonDirector

Author

Commented:
Thank you
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

Commented:
Glad I could help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial