我有一个ASP.NET Web API控制器。我想为不同的环境设置不同的URL结构,我该怎么做?我们可以在Web.Config中解决路由吗?
例如在dev中我想要host / dev / api / controllername,对于Production我想要host / api / controllername
我该怎么做?
答案 0 :(得分:0)
我认为您可以在web.config中添加一个键来指定环境。 例如:
<profiles>
<!-- This default not needed since is specifies nothing, but this seems to be the correct syntax if it were needed
<profile>
<id>Default-CPP-Tools</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
-->
<profile>
<id>Windows-MinGW</id>
<activation>
<os>
<family>Windows</family>
</os>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<version>3.5.1</version>
<extensions>true</extensions>
<configuration>
<linker>
<name>g++</name>
<options>
<option>-Wl,--kill-at</option>
</options>
</linker>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<defaultGoal>integration-test</defaultGoal>
<plugins>
<plugin>
<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<version>3.5.1</version>
<extensions>true</extensions>
<configuration>
<libraries>
<library>
<type>jni</type>
<narSystemPackage>com.mycompany.sandbox</narSystemPackage>
</library>
</libraries>
</configuration>
</plugin>
</plugins>
</build>
然后,在Application_Start中,您从web.config中读取此配置的值并相应地注册路由。
<add key="Environment" value="Development" />