1

I have 2 applications.

I want frontend (react) to be available on url: localhost:5001/ekadry

and backend (web api in c#) to be available on url: localhost:5001/ekadryapi

This is how it looks like in IIS: enter image description here

When I go to each of these urls each app seems to be working. The problem occurs when frontend requests something from backend - then I get an error 405 Method Not Allowed:

enter image description here

The problem DOES NOT occur when backend and frontend are hosted on different ports as different Web Sites. Can someone explain it to me?

3
  • See this if it helps - stackoverflow.com/questions/59485621/… Commented Feb 9, 2021 at 10:26
  • try to remove the WebDAV feature from the iis. by unchecking the feature.image restart iis after making changes. Commented Feb 19, 2021 at 9:56
  • It is not a WebDAV problem because I don't have it Commented Feb 22, 2021 at 10:06

2 Answers 2

1

I added this rule in web.config and now frontend can access backend. Problem solved.

    <rule name="ReactRouter Routes" stopProcessing="true">
      <match url=".*" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_URI}" pattern="^/ekadryapi(.*)$" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      </conditions>
      <action type="Rewrite" url="/index.html" />
    </rule>
Sign up to request clarification or add additional context in comments.

Comments

0

I think you have to grant access to clients in API web.config

Something like below tags:

<configuration>
<system.webServer>
   <httpProtocol>
        <customHeaders>
            <add name="Access-Control-Allow-Origin" value="*" />
            <add name="Access-Control-Allow-Headers" value="Content-Type, Token, Accept, 
            Accept-Language, Content-Language,X-ATJ-Auth-Token,X-ATJ-Username" />
            <add name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE,OPTIONS" />
        </customHeaders>
   </httpProtocol>
    <handlers>
      .
      .
      .
    </handlers>
  </system.webServer>
</configuration>

1 Comment

Thanks for the answer. I added these lines to web.config in web api but I don't see a difference, still same error :(

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.