Reactjs 将React站点托管在与WCF服务相同的文件夹中
我已经通过GoDaddy在一个共享的Windows主机上建立了一个现有的WCF服务,我希望将react应用程序上传到同一个主机上以使用该服务 例如,我在Reactjs 将React站点托管在与WCF服务相同的文件夹中,reactjs,wcf,shared-hosting,Reactjs,Wcf,Shared Hosting,我已经通过GoDaddy在一个共享的Windows主机上建立了一个现有的WCF服务,我希望将react应用程序上传到同一个主机上以使用该服务 例如,我在https://example.com/Service1.svc/当您输入https://example.com我希望react应用程序可见,并且仍然能够通过现有url访问服务 我不确定如何配置我的web.config以满足此要求。导航到根域会出现404错误,尽管文件存在,但尝试导航到index.html也会出现404错误。如果我清除了web.c
https://example.com/Service1.svc/
当您输入https://example.com
我希望react应用程序可见,并且仍然能够通过现有url访问服务
我不确定如何配置我的web.config以满足此要求。导航到根域会出现404错误,尽管文件存在,但尝试导航到index.html也会出现404错误。如果我清除了web.config,react站点将正常工作,但显然该服务不再工作
以下是我的网页配置:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<trust level="Full" originUrl="" />
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000" />
</webServices>
</scripting>
</system.web.extensions>
<system.serviceModel>
<services>
<service name="MyService.Service1" behaviorConfiguration="web">
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="httpBinding"
contract="MyService.IService1" />
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="httpsBinding"
contract="MyService.IService1" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="web">
<serviceMetadata httpGetEnabled="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp helpEnabled="true" defaultBodyStyle="Bare" faultExceptionEnabled="true"
automaticFormatSelectionEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
<bindings>
<webHttpBinding>
<binding name="httpBinding">
<security mode="None" />
</binding>
<binding name="httpsBinding">
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaders>
</httpProtocol>
<staticContent>
<clear />
<mimeMap fileExtension="." mimeType="*/*" />
<mimeMap fileExtension=".txt" mimeType="*/*" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
</configuration>
或者,我发现我可以将服务放在一个子文件夹中,并配置一个虚拟目录,使其在那里工作,但是这会将服务的URL更改为http://example.com/subfolder/Service1.svc
这在现阶段是不可取的。有没有办法让原始URL以某种方式指向子文件夹中的服务
任何帮助都将不胜感激。我想我已经解决了。起初,我认为这与服务中的某些配置有关,阻止了其他一切,结果证明我几乎是对的,只是它与服务本身无关,与web.config的这一部分有关:
<staticContent>
<clear />
<mimeMap fileExtension="." mimeType="*/*" />
<mimeMap fileExtension=".txt" mimeType="*/*" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
具体来说,这一行清除了现有的内容处理程序,因此服务器甚至无法提供组成react站点的HTML和js文件。它们支持完全信任吗?据我所知,他们不支持。我以前用过,他们不支持。