Configuration Error related to targetFramework in web.config - asp.net

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:
And NuGet Package Manager:
EntityFramework Reference Properties:
Default Web Site Basic Settings: (To be honest, I am not sure whether I should add a new website(my website) in here.)
My installed .net frameworks:
My publish method:
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:
changing this compilation tag
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.
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?

Your website project is targeting v4.6 of the .NET Framework but your hosting provider has not yet installed this version. Your options:
Ask provider to install it - they are unlikely to do this.
Find another provider that does support it.
Change your project to target v4.5.

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 your best bet to check the current state of what all components are installed on your machine (Refer screenshot)
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 itself.

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

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.

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)

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.

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">

Related

CAS policy Error

please, someone can help me to fix this error, "This method implicitly uses CAS policy, which has been obsoleted by the .NET Framework. In order to enable CAS policy for compatibility, please use the NetFx40_LegacySecurityPolicy configuration switch." I can not generate my pdf files. it's an Asp.Net application to host on a Win 2008 R2 server. IIS 6.5. I already added
<runtime>
<NetFx40_LegacySecurityPolicy enabled="true" />
</runtime>
in my web.config but it did not solve the problem.
The error occurs because CAS policy is obsolete in .net Framework 4.0. The Xml node you've added is for Windows Forms applications. For Web applications, please add the following in web.config:
<system.web>
<trust legacyCasModel="true"/>
</system.web>

Is there a "release" configuration for ASP.NET Web Sites?

I use Visual Studio for Website development (VS 2010 Ultimate and VS 2012 Professional). To be more specific, I created this website by File > New Web Site, so I do not believe this is a project.
While developing the website, I have debug="true" enabled in the web.config file. When I publish, I manually change to debug="false".
<configuration>
<system.web>
<compilation debug="true" strict="true" explicit="true" targetFramework="4.5">
</system.web>
</configuration>
There are two config files in the solution: "web.config" and "web.Debug.config".
This is what the various forum articles and "Programming ASP.NET" books say to do, but I wonder if there is a way to have debug="true" for local development and automatically switch to debug="false" when using Build > Publish Web Site so I don't have to manually change the web.config file?
According to this forum answer, "There is no way to have a Release configuration for your website."
Keeping in mind that this is a Web Site and not a project, it looks like adding another config based on comment suggestions might not be possible. A possibly valid answer is "no, it is not possible in this context."
Is there another way to achieve the intended outcome without using the current workaround of manually changing the debug setting?
Sorry, it's related to it being a "web site" type project, which aren't compiled:
Configuration of publishing an ASP.NET web site
To quote the previous responder above:
"Web Site projects don't have the Release configuration available, but it makes no difference since they are not compiled. Web Application projects, on the other hand, do get compiled and have both configurations available."
According to the available references, for "ASP.NET Website" it is not possible to have a separate release configuration.
So the answer to the posed question is no: it is not currently possible. Manually changing the debug attribute when you publish and then changing it back is the only option in that case.
How can you proceed? If you really need to have a release configuration and a debug configuration, the a possible option is Converting a Web Site Project to a Web Application Project. While not a direct answer to the presented question, it is an alternative.
For some projects I've set up an Environment appSetting and scoped all other keys off of that Environment.
For instance:
<add key="Environment" value="Development"/>
<add key="Development.Title" value="My Dev App"/>
<add key="Production.Title" value="My Production App"/>
<connectionStrings>
<add name="DbContext.Development" connectionString="Initial Catalog=DatabaseDev;...."
providerName="System.Data.SqlClient" />
<add name="DbContext.Production" connectionString="Initial Catalog=DatabaseProd;...."
providerName="System.Data.SqlClient" />
</connectionStrings>
Then you would create a Configuration class that would pull appSettings and connectionStrings by looking for:
appSetting
string.Format("{0}.Title", ConfigurationManager.AppSettings["Environment"])
connectionString
string.Format("DbContext.{0}", ConfigurationManager.AppSettings["Environment"])
Not perfect but this will let you only have to replace one web.config value instead of a bunch without the help of the Publish config transform.

ASP.NET TargetFramework attribute isn't recognized

I have been trying to make a project, but in web.config, it keeps giving me the error that it doesn't recognize the attribute TargetFramework.
EDIT: Added the web.config. I have seen one question with the same problem and they said there that it should be the same version as the version of ASP.NET. But i don't really see how to do that.
P.S. i can't change to a different version of Visual Studio (i use that program) since it won't allow me to run the files on local web. But that's a different problem.
Been a while now. Guess it's a tough problem.
<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true" targetFramework="4.0">
<assemblies>
</assemblies>
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/> </system.web>
<system.codedom>
</system.codedom>
<!--
The system.webServer section is required for running ASP.NET AJAX under Internet
Information Services 7.0. It is not necessary for previous version of IIS.
-->
<system.webServer>
</system.webServer>
</configuration>
This happens basically when you have an attribute of targetFramework="4.0" in the web.config but the App Pool is set to run ASP.NET 2.0. The targetFramework attribute is entirely unrecognized by ASP.NET 2.0 -This means it will not work even if you changed it to 2.0 in config file.
If your application is coded in 4.0 then the AppPool is need to be set up to 4.0
In IIS > Right click on WebSite > Properties > ASP.NET > Version > "Should read 4.0.21006" not 2.0
I've gotten this error when trying to use Fortify with Visual Studio. The Visual Studio Fortify plugin seems to want to use the aspnet_compiler instead of msbuild. It was throwing that exact message.
When I used the command line tools to have Fortify compile using msbuild, it worked. Perhaps your Visual Studio is not using msbuild? You may want to try converting it to a web application if it's not already. I think then Visual Studio will use MSBuild by default. Not sure if this is your problem, but I did get that exact same error message. Good luck.

.NET Web API 2 Project downloading browserLink.js

I've got a .NET Web API project and on load I'm getting a download of this script called browserLink.
http://localhost:49818/ea93983f23c54f35a63de09646c09159/browserLink
Its associated with .NET Signalr but I'm not using that so I'm not sure why its being included. Any ideas how to turn it off?
Disable Browser Link in Visual Studio 2013.
Do this by editing your web.config file to add the following line to your appSettings section:
<appSettings>
<add key="vs:EnableBrowserLink" value="false"/>
</appSettings>
Note that Browser Link is only used when working in Visual Studio AND the web application is compiled in debug mode, i.e.:
<system.web>
<compilation debug="true" />
</system.web>
In other words, end-users of your site will never make this request.

Is it possible to host an aspx (.NET 4.0) website locally on Windows 8 Enterprise?

As the title states is it possibly to host a dynamic (that would be .aspx correct?) website locally (IIS 8) on a computer running Windows 8 Enterprise? I've installed all the IIS components, added the website as many guides on Google will show but I get error 9 as stated here:http://support.microsoft.com/kb/942055
my web.config is as follows:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="false" targetFramework="4.0"/>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
I also have the correct version set for the site (.NET 4.0) and tried resetting all feature delegations. At this point I'm thinking of just doing a cheese puff solution and just running the site via the built in server within Visual Web Developer.
"Stock" ASP.NET Web.Config file
When I create a standard, empty ASP.Net Web Forms Application targeting .NET Framework 4.0, here's the standard Web.config file that's generated:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections />
<connectionStrings />
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" defaultUrl="~/" />
</authentication>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
EDIT: I removed the Membership, Role, Profile, and SessionState sections that were previously here. These aren't, strictly, required but are part of the standard Empty ASP.Net Web Forms Application template to help you get started quickly. What is shown above is the minimum Web.config you need.
NOTE: Don't worry about the debug="true" in the <Compilation /> element. You should have that attribute set to false in production anyway.
I Suspect it's your IIS Configuration
After re-reading your question, I suspect that you haven't properly configured IIS to host the site properly.
First, I want to start by saying that there's Internet Information Services (IIS), the actual web server, that can be installed on Windows 8 as well as server OSes such as Windows Server 2012. There is also IIS Express, used for development and which is a replacement for the old Development Web Server (code-named Cassini) in VS2008 and VS2010 (prior to SP1 when IIS Express was made available through an additional installation).
It sounds to me like you have installed IIS under Windows 8 Program and Features. Now you need to create a site in IIS that points to where your web application is located on your hard disk.
Open IIS Manager
Expand your machine name in the Connections pane on the left.
Expand the Sites folder. There should already be a site called Default Web Site.
Right-click the Sites folder and choose Add Website....
Give the site a name. Choose the DefaultAppPool for now (you can change it later).
Under Physical path, browse to where your web site/application is located on your hard disk.
Click OK.
There are other options on that page and you can find help on them at MSDN. That may be enough to get you started, though.

Resources