46

I have made an MVC website in Visual Studio 2015 and it works in my localhost. But when I published my website and put into my host, it doesn't work. It gives me this error notice:

Server Error in '/' Application.

Configuration Error

Parser Error Message: The 'targetFramework' attribute in the element of the Web.config file is used only to target version 4.0 and later of the .NET Framework (for example, ''). The 'targetFramework' attribute currently references a version that is later than the installed version of the .NET Framework. Specify a valid target version of the .NET Framework, or install the required version of the .NET Framework.

Source Error:

An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

Source File: G:\xxx\xxx.com\httpdocs\web.config Line: 24

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34248

Related parts in my web.config:

  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>

And this part with error:

  <system.web>
    <authentication mode="None" />
    <customErrors mode="Off" />
    <compilation debug="true" targetFramework="4.6" />
    <httpRuntime targetFramework="4.6" />
  </system.web>

Properties of my website:

enter image description here

And NuGet Package Manager:

enter image description here

EntityFramework Reference Properties:

enter image description here

Default Web Site Basic Settings: (To be honest, I am not sure whether I should add a new website(my website) in here.)

enter image description here

My installed .net frameworks:

enter image description here

My publish method:

enter image description here

I have investigated this problem on the Internet and I have found several links related to my problem: Asp.net MCV4 framework issue. In this link, there are two main offers:

  1. changing this compilation tag

  2. updating application pool in IIS

Actually, I have tried to change this tag but it doesn't change. Then I have controlled my application pool but it seems up-to-date.

enter image description here

I have called my host provider and I have explained my problem. They say that this error is not related to their servers.

What should I do? What is the solution for this?

8
  • 2
    Is .Net Framework 4.6 installed on the server? Commented Oct 29, 2015 at 10:44
  • @DavidG to be honest, i didn't ask this my host provider. but in localhost .net framework 6 is installed. i am adding its picture. Commented Oct 29, 2015 at 10:53
  • So are you saying when you publish to your local IIS, it's not working? Or just when you publish to your hosting provider? Commented Oct 29, 2015 at 10:59
  • 1
    You server need to Install .Net Framework 4.6 Commented Oct 29, 2015 at 11:02
  • 2
    Yes, your application is asking for v4.6. Change the project to target 4.5 instead. Commented Oct 29, 2015 at 11:17

8 Answers 8

62

Your website project is targeting v4.6 of the .NET Framework but your hosting provider has not yet installed this version. Your options:

  1. Ask provider to install it - they are unlikely to do this.
  2. Find another provider that does support it.
  3. Change your project to target v4.5.
Sign up to request clarification or add additional context in comments.

Comments

14

I'm adding one more information to complement DavidG's answer. If Internet Information Server (IIS) is your provider then Web Platform Installer (an IIS extension) is a very helpful tool. It can be your best bet to check the current state of what all components are installed on your machine (Refer screenshot)

enter image description here

It is very easy to check what all components are missing from your computer. Based on that, you can kick-start installation of any missing component through the UI of this IIS extension.

3 Comments

Very useful, thanks @RBT, helped resolve the issue I had in a few minutes!!
The Microsoft Web Platform Installer (WebPI) was retired on December 31, 2022.
You edited this. A better action would have been to delete the answer since this program isn't available any more.
2

I just had a similar problem following the installation ( windows update) of the KB 3205402.

Big difference with my case: the application worked well before the update !

==> I found in "IIS Manager", in "ISAPI and CGI Restrictions", that the framework ASP.NET v4.0.30319 has been switched to "unauthorized" !

Switching it to "Authorized" resolved my problem

Comments

2

I changed:

<system.web>
    <compilation debug="true" targetFramework="4.7" />
    <httpRuntime targetFramework="4.7" />
    <customErrors mode="Off"/>
  </system.web>

to

<system.web>
     <compilation debug="true" targetFramework="4.5" />
     <httpRuntime targetFramework="4.5" />
     <customErrors mode="Off"/>
</system.web>

i.e, changed targetFramework value to 4.5 (the one supported on server) from 4.7. and worked.

Comments

1

had the same issue on the below line on an offline server ,

 <compilation targetFramework="4.5.2">

tried adding all the roles and features related to .Net framework from the server manager and to its pool ,

but didn't work , what worked for me is just downloading Microsoft .NET Framework 4.5.2(Offline Installer)

1 Comment

I had the same issue but with version 4.7.2., I just installed the version in the windows server and worked, thanks!
1

I tried replacing the targetFramework 4.5.2 to targetFramework 4.0 directly in config file. Then it and all the functions work correctly.

Before:

<compilation targetFramework="4.5.2">

After:

<compilation targetFramework="4.0">

Comments

0

I went round and round with this today with no resolution. Exasperated, I finally just deleted my working copy from my drive, and rechecked it out from SVN.

Fixed.

Not a particularly clever answer, but it fixed it for me, no idea what the actual problem was.

Comments

0

I got the same error because my application pool was setted up to .NET Framework 2.0

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.