3

I am not sure if this has been asked before. I am trying to deploy my two web applications to an azure web app, an asp.net web form application and an asp.net web api. I do know that I can create two different directories and then put my two applications to those two directories. However when I do that and configure like the first image below, my web app works well but my web API get a problem, an error from the web.config file of the web application is shown. I've tried to disable my web application then the web API worked well after that.

This is what my folders look like:

enter image description here

And this is the error that I get:

Click here to see my error

There is a similar thing that has been posted before here Azure multiple sites in virtual directories but in my case, our applications are not built on ASP.NET CORE

Update:

  • I have also tried to add the "System.Web.Optimization" dll to the web api project just to have a try (it actually is not needed) and after that I see another error.
  • Lines of code you see in the error image is just from web.config of the web application, that should not be a problem when I try to access the web api.

3 Answers3

1

I have solved my own problem. web.config files are inherited from root level as default, I tried to add <location path="." inheritInChildApplications='false'> to cover all sections (exclude ones that don't allow to do this) inside the web.config file of the web app (in this case, it's the root web.config file).

For instance

<location path="." inheritInChildApplications='false'>
  <connectionStrings>
    <add name="ApplicationDbContext" connectionString="Data Source=.;Initial Catalog=xxx;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="AngularAppName" value="angularApp" />
  </appSettings>
  <system.web>
    <customErrors mode="Off" />
    <compilation debug="true" targetFramework="4.6.1" />
    <httpRuntime targetFramework="4.6.1" />
    <pages>
    <namespaces>
            <add namespace="System.Web.Optimization" />
          </namespaces>
      <controls>
        <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
      </controls>
    </pages>
  </system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
  <entityFramework>

    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  </location>

Following this article https://www.hanselman.com/blog/ChangingASPNETWebconfigInheritanceWhenMixingVersionsOfChildApplications.aspx

0

You need Add new virtual application or directory under Application Settings page from your Azure web app

trungduc
  • 11,926
  • 4
  • 31
  • 55
0

Lines of code you see in the error image is just from web.config of the web application, that should not be a problem when I try to access the web api.

As the second image you provided, when you visit some specific controller in api it also get error, so it means you could not get the web api correctly.

I try to test and fail not reproduce your error message. You could refer to this thread to follow the detail steps to create a virtual directory.

According to your error message, you could try the several ways to troubleshoot:

1.Uninstalled and reinstalled the nuget packages(update to the latest).

2.Try to install Microsoft.AspNet.Web.Optimization via nuget(you do not work).

3.Set property CopyLocal=True for System.Web.Optimiszation.

4.Set the web.config as below, and refer to this issue.

<configuration>
  <system.webServer>
    <handlers>
      <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
  </system.webServer>
</configuration>
Joey Cai
  • 18,968
  • 1
  • 20
  • 30
  • After editing web.config, I see this error message: "The specified CGI application encountered an error and the server terminated the process." – tuan nguyen Jul 02 '18 at 08:02
  • In the `httpPlatformremove` the `forwardWindowsAuthToken="true/false"` property, refer to this [thread](http://www.brandonmartinez.com/2015/10/28/resolve-an-asp-net-dnx-httpplatformhandler-cgi-application-exception-on-azure/). – Joey Cai Jul 02 '18 at 09:44