Reputation: 172200
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:
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?
Upvotes: 2
Views: 8132
Reputation: 172200
@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>
Upvotes: 0
Reputation: 27962
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:
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:
Upvotes: 1