5

Application = Blazor Web Assembly PWA Framework 6.0

API = Rest Api .netcore Framework 5.0

WEB Address = localtesting.mydomain.com

API Address = (localtesting.mydomain.com/api) Virtual directory.

I created virtual directory and uploaded my API in virtual directory. APi Works fine as expected

Then i try to upload Blazor WASM on root folder but when i do so API stops working. As wasm is redirecting URL.

I think its due to fallout rule from blazor which is handled by web.config

i tried to edit web.config but cant get it to work

so i am tryig to add a rule in web.config to not intercept requests for API.

api response when Blazor WebAssembly is not published on Plesk There is no one here but Awhen upload Blazor WebAssemblyPI when uploading Blazor WebAssembly

No data when

i have tried to edit web.config but still cant get it to work as blazor redirects all requests to wwwroot folder

Following is the web.config file

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <staticContent>
      <remove fileExtension=".blat" />
      <remove fileExtension=".dat" />
      <remove fileExtension=".dll" />
      <remove fileExtension=".json" />
      <remove fileExtension=".wasm" />
      <remove fileExtension=".woff" />
      <remove fileExtension=".woff2" />
      <mimeMap fileExtension=".blat" mimeType="application/octet-stream" />
      <mimeMap fileExtension=".dll" mimeType="application/octet-stream" />
      <mimeMap fileExtension=".dat" mimeType="application/octet-stream" />
      <mimeMap fileExtension=".json" mimeType="application/json" />
      <mimeMap fileExtension=".wasm" mimeType="application/wasm" />
      <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
      <mimeMap fileExtension=".woff2" mimeType="application/font-woff" />
    </staticContent>
    <httpCompression>
      <dynamicTypes>
        <add mimeType="application/octet-stream" enabled="true" />
        <add mimeType="application/wasm" enabled="true" />
      </dynamicTypes>
    </httpCompression>
    <rewrite>
      <rules>
        <rule name="Serve subdir">
          <match url=".*" />
          <action type="Rewrite" url="wwwroot\{R:0}" />
        </rule>
        <rule name="SPA fallback routing" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          </conditions>
          <action type="Rewrite" url="wwwroot\" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

    enter code here
H.M.Mubashir
  • 170
  • 1
  • 14
  • Maybe the endpoint of the api is on the same por as the blazor app? – hesolar Sep 22 '22 at 12:05
  • How can I set the endpoint in Blzor WebAssembly there is no Startup.cs file like in Blazor Server – H.M.Mubashir Sep 24 '22 at 06:39
  • First you need to check if the two projects are deployed to different ports or if they are deployed to the same port. – hesolar Sep 26 '22 at 06:22
  • sorry @hesolar that was the not problem. If I upload Blazor server-side API responds correctly. The problem is only in Blazor WebAssembly.When I upload Blazor API doesn't respond. – H.M.Mubashir Sep 28 '22 at 10:27
  • Looks like you need to enable CORS policy. similar here: [stack overflow answer](https://stackoverflow.com/questions/18619656/enable-cors-in-web-api-2) – Drew Aguirre Oct 03 '22 at 00:04
  • @HenkHolterman i have edited the question. can you please let me know which iis configration do u think may be causing this issue – H.M.Mubashir Oct 03 '22 at 05:17
  • @DrewAguirre follwing is my CORS policy services.AddCors(o => o.AddPolicy("MyPolicy", builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); })); – H.M.Mubashir Oct 03 '22 at 05:22
  • 405 means method not allowed.. maybe you need to check your HTTPverb, for example you are using a POST api call on a GET endpoint.. – Drew Aguirre Oct 03 '22 at 23:57
  • The wasm is expected to be served from www folder of the application by default. Web.config is connected with IIS and has nothing to do with your blazor app. How is the API configured? did you by any chance overwrite any files regarding the API when moving the wasm files to root folder? – Surya Pratap Oct 04 '22 at 07:34
  • @DrewAguirre my HTTPverb is correct because if I request a API before uploading Blazor WebAssembly, app responds correctly whenever upload Blazor WebAssembly and after send the request then error comes like 405 or etc. – H.M.Mubashir Oct 05 '22 at 05:30
  • Thanks, @HenkHolterman this is useful info but I need some more – H.M.Mubashir Oct 07 '22 at 04:34
  • @H.M.Mubashir on properties folder, launchsettings.json file you can set the starting url – hesolar Jan 03 '23 at 11:47

1 Answers1

1

by adding the following code in the config.Proj file

<location path="." inheritInChildApplications="false">
</location>
H.M.Mubashir
  • 170
  • 1
  • 14