Cannot open/create ASP.NET applications in Visual Studio 2019 - asp.net

I'm having trouble opening my projects in Visual Studio. I get the following error and the project does not load.
Creation of virtual directory failed with the following error: Filename: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config
Line number: 24
Error: The configuration section 'fulltrustassemblies' cannot be read because it is missing a section declaration.
I tried creating a new ASP.NET webform application with target framework 4.7.2 (same as the ones of the project that does not load) and get the same issue.

Did you try if adding the section to the file solve the problem?
<configuration>
<system.webServer>
<system.web>
<fullTrustAssemblies>
<clear/>
</fullTrustAssemblies>
</system.web>
</system.webServer>
</configuration>

In the respective web.config file, you need to removed following element:
<fullTrustAssemblies>
....
</fullTrustAssemblies>
<partialTrustVisibleAssemblies />

Related

Enable directory browing for ASP.NET projects published from Visual Studio

I am trying to import an ASP.NET project which I know works and I am trying to build it on local. I imported the solution file in Visual Studio and went ahead and did a Clean and Build on it which went ok. Now I am trying to Publish the project and once I do that, I clicked the run button which says IIS Express and I see the following
HTTP Error 403.14 - Forbidden
Most likely causes:
A default document is not configured for the requested URL, and directory browsing is not enabled on the server.
If I was running this application out of IIS Manager, I know how to resolve this by clicking on the project, clicking Directory Browing and clicking Enable but I don't know how to fix this issue if I am running it from inside Visual Studio.
To resolve the issue you could try one of the below ways:
1)Set the below code in the web.config file:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true" />
</system.webServer>
2)Set the default page for your project:
<system.webServer>
<defaultDocument>
<files>
<add value="pagename.aspx" />
</files>
</defaultDocument>
</system.webServer>
if you are using the MVC site then set default routs.

IIS error 500.19 error when reading web.config

I am running IIS under Windows Server 2016 and I'm trying to run an ASP.Net core 3.1 application but I can't get past this error:
500.19 error
(The language in the picture is Hungarian, but it contains no useful information whatsoever, just an example)
Here is my web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\Minibizz.Routing.Web.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
What am I missing?
P.S.: The web.config was created by Visual Studio 2019.
The reason behind the issue:
That error message goes on to say what exactly is bad about your configuration file, hence you should refer the “Config Error” and “Config Source” sections. This problem occurs because of the ApplicationHost.config file or the Web.config file contains a malformed or unsupported XML element.
if you are using url rewrite rule then install url rewrite Extention of iis. Enable ANCM logging, ie. set stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout\" (I think the path needs to end by a backslash), then run the web app and see if something gets logged into the stdout folder. Verify that the log directory exists at the path referenced by the web config. If it does not, create it. The path shown in your config would place the "logs" directory in the root folder of the deployed site. Verify that the application pool has to write access to the logs directory.
Make sure you installed the .net bundle.check that you installed below iis feature:
You may also need to verify that the path to the dotnet executable exists in the deployment machine's environment variables. To check this, first find the path where dotnet.exe is installed. It is generally located in either C:\Program Files\dotnet or C:\Program Files (x86)\dotnet. Once you know the path, ensure that the path exists in your Environment Variables.
The web.config content seems to be correct. If you use a clean web.config copy, does the problem persist? If the issue can be solved by replacing web.config with clean configuration content, then the problem is exactly with this web.config. In this case, I suggest you remove parts of the web.config content to narrow down the issue. If the pages show correctly after you remove one section, then the problem is with that section. You need double-check what's wrong with the section and update the correct configuration.
If the problem remains even with clean web.config content, I suggest you access other pages in different folders in your site to see if the problem still exists.
you could refer this below link for how to publish asp.net core site in iis:
https://learn.microsoft.com/en-us/aspnet/core/tutorials/publish-to-iis?view=aspnetcore-3.1&tabs=visual-studio

How to set debug false for release mode

I have this web.config file with the compilation option set as below
Web.config
<configuration>
...
<system.web>
<compilation debug="true" targetFramework="4.5" />
...
</system.web>
</configuration>
And here is what Visual Studio puts for release mode by default.
Web.Release.config
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
</configuration>
I am using this for MVC4 project. Based on this tutorial, I was expecting that minified versions of js and css would be served, when the application is run under Release Mode. But this doesn't seem to be working and non-minified versions of js and css are being served. On the other hand, if I explicitly set debug to false in web.config, then the min versions are served correctly.
It seems like compilation tag Transform issue when the application is run under Release Mode, but I don't understand what's wrong with the same in Web.Release.config.
In short, I am unable to get bundling and minification working, by running application under Release Mode.
Web.config transformations as they are defined in the Web.Release.config are only done when deploying/publishing the project for the relevant configuration.
Just changing the active configuration in Visual Studio to Release and running the application does not run the transformations. Therefore, the web.config remains unchanged. This behavior is reasonable by the way as a web application is run from the project directory that contains the original web.config. If Visual Studio were to transform the web.consign, your original web.config would be changed.
If you haven't created a deployment profile yet, you can publish your application to the file system to verify the behavior. Choose Release as the configuration to run the deployment for. The transformations should be executed as expected.
My answer might be late, however this what worked with me:
I've changed the line :
<compilation xdt:Transform="RemoveAttributes(debug)" />
to :
<compilation xdt:Transform="Replace" debug="false" targetFramework="4.5" />
this basically did the trick, as I think the optimizer is looking for Debug value to be be present and == "false".
Hope this helps people who don't want to manage this from code.
If you'd like to test your .NET bundling and minification that you've got set up in your Global.asax file, you can also use precompilation notation...for example
#if DEBUG
BundleTable.EnableOptimizations = false;
#else
BundleTable.EnableOptimizations = true;
#endif
With this, your application won't need to trigger the transform in the build operation and will run just like you want it to.
Possibly an improvement to Omar.Alani's answer:
In the Release transform, replace the line:
<compilation xdt:Transform="RemoveAttributes(debug)" />
with the following:
<compilation debug="false" xdt:Transform="SetAttributes" />
compilation debug="false" xdt:Transform="SetAttributes"
comes in handy when you are activating XML transformations at release azure deployment time to make configuration transformations specific to a target environment.
When you check XML transform at azure deployment time, the following sequence is done:
Apply web.release.config on web.config
Apply web.stageName.config on modified web.config.
But web.release.config has already been applied on web.base.config so if
compilation xdt:Transform="RemoveAttributes(debug)"
is used in web.release.config file, the web.config has already debug attribute been removed at compilation time and when it deploys it transform again with web.release.config, trying to apply the above command but it fails.
Removing debug attribute is sufficient RemoveAttributes(debug).
It will work similar to debug=false.

Server Error in '/' Application. This type of page is not served

I have an host where I hosted a webpage with .cshtml extension. My host is arvixe.com that provides ASP and .NET hosting but when I try to load my web page I get this error message.
Server Error in '/' Application.
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.cshtml' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /samples/WoT/Default.cshtml
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.276
I read something does I have to write something in my web.config file to make it work
like this
<compilation>
<assemblies>
<add assembly="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
<buildProviders>
<add extension=".cshtml" type="System.Web.WebPages.Razor.RazorBuildProvider, System.Web.WebPages.Razor"/>
</buildProviders>
</compilation>
But I tried everything, paste it in on different lines, nothing worked. What do I miss or do wrong?
I believe you are not making using the MVC feature and trying to load just the razor view outside views or custom Area folders.
Then you need to enable webpages key in Web.config which is disabled by default in .Net 4.0
<add key="webpages:Enabled" value="true" />
<appSettings>
<add key="webpages:Enabled" value="true" />
Repairing this in Windows 10 Pro using IIS 10 was a nightmare, it took two days but I was finally able to achieve the desired results using the following procedure:
Open your web site in Visual Studio. The way you do this is to go to File > New > Web Site and then select ASP.Net Empty Web Site AND before you click OK change the location to your project location. In my case I had my project in C:\inetpub\wwwroot\AspNet\Projects\Test
Open internet information services manager (click the "cortana" search and type IIS, it should show up as long as you have it installed). Locate your project folder under the ServerName > Sites > Default Web Site > ... , right click on it and click the "Convert to web Application" button. Accepting the defaults at the prompt by clicking OK should be sufficient in most cases.
Use the following Web.Config file, or something similar. NuGet may overwrite some settings but this isn't a big problem.
<?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=301879
-->
<configuration>
<appSettings>
<add key="webPages:Version" value="3.0.0"/>
<add key="webpages:Enabled" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
</assemblyBinding>
</runtime>
</configuration>
Delete your bin folder, and packages.config file, if they exist. This is because we must assume that something in that bin folder is corrupt since IIS is designed to run Razor/ASP. In your visual studio project you will need to refresh your project so it knows these files have been deleted. This can be done by clicking the refresh button in the menu on the top of the Solution Explorer frame. In you visual studio project go to Tools > NuGet Package Manager > Package Manager Console and enter the following two commands.
Install-Package Microsoft.AspNet.Razor -Version 3.0.0
Install-Package Microsoft.AspNet.WebPages
This was enough to get *.cshtml pages to be rendered by IIS 10 on Windows 10 Pro.

Could not load file or assembly 'App_Licenses' or one of its dependencies. Access is denied

Has anyone ever come across this? I've never seen it before. I know there is a *.lic" file in my bin for some web charting software.
I did a publish, copied to dev server and then suddenly boom, get this error on every page.
Any ideas? I've cleared out temp asp.net files and restarted IIS.
edit:
wow, I'm thinking this might be the TumbleWeed badge.
Add this to your web.config:
<configuration>
<system.web>
<compilation>
<buildProviders>
<remove extension=".lic"/>
<add extension=".lic" type="System.Web.Compilation.ForceCopyBuildProvider"/>
</buildProviders>
</compilation>
</system.web>
</configuration>
The problem was the NETWORK SERVICE lost it's permission to the bin directory.
I was getting same error and tried giving full rights to "Everyone" on bin folder but didn't solve problem. I was using VS2010 on windows 7. Running visual studio as administrator solved my problem.

Resources