2

I have an ASP.NET WebForms application which requires .NET Framework 4.8 (or higher). I want the application to "fail early" if the required framework version is unavailable (e.g. on a system with only 4.7 installed). In other words, I want something like the supportedRuntime tag for executables, just for web applications.

Can this be achieved via some web.config setting? I have tried:

  • system.web/httpRuntime/targetFramework
  • system.web/compilation/targetFramework
  • startup/supportedRuntime/sku (just for completeness, I didn't expect it to work)

I.e.:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  ...
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
  </startup>

  <system.web>
    <httpRuntime targetFramework="4.8" />
    <compilation targetFramework="4.8" />
    ...
  </system.web>
</configuration>

However, the web application still happily runs on a server with only .NET Framework 4.7 installed.

Did I miss anything or is this feature just not available?

4
  • Just out of curiosity, how this "fail early" should look like for a web app? Return 500 for every request? Commented Jun 23, 2019 at 20:50
  • @WiktorZychla: Yes, return 500 (with a descriptive and helpful error message, if customErrors/mode allows) would be great. Commented Jun 23, 2019 at 20:58
  • A simple runtime check in Application_Start should fail pretty early (you could even pull the version to check against from web.config) stackoverflow.com/questions/951856 Commented Jun 24, 2019 at 1:53
  • @DaveM: Yes, that was my backup plan. I just wanted to make sure that I didn't reinvent the wheel first. Commented Jun 24, 2019 at 14:33

2 Answers 2

1

As far as I know, if you don't install the .net framework 4.8, if you run yur web application on IIS, it will show below error:

enter image description here

I suggest you could try to follow below steps to check you have installed the .net frameworr 4.8:

1.From the Start menu, choose Run, enter regedit, and then select OK.You must have administrative credentials to run regedit.

2.In the Registry Editor, open the following subkey: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full. If the Full subkey isn't present, then you don't have the .NET Framework 4.5 or later installed.

3.Check for a DWORD entry named Release. If it exists, then you have .NET Framework 4.5 or later versions installed. Its value is a release key that corresponds to a particular version of the .NET Framework. In the following figure, for example, the value of the Release entry is 528040, which is the release key for .NET Framework 4.8.

Result:

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

You are right, <compilation targetFramework="4.8" /> does work. I did some more research and discovered why it didn't work in my case - see my answer for details.
1

@BrandoZhang's answer is correct, <compilation targetFramework="4.8" /> does work. I added this answer to explain why it didn't work in my case. (Too long for a comment, and it might help someone with the same problem.)

In my case, web.config wasn't located in the web application's directory. It was located in the parent directory, because I have multiple web applications that need to be configured in exactly the same way and I did not want to repeat myself.

It turns out that, apparently, compilation's targetFramework attribute does not get inherited by child applications (if you know why, feel free to leave a comment). Adding the following web.config file directly in the application's directory fixed the issue for me:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <compilation targetFramework="4.8" />
  </system.web>
</configuration>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.