简体   繁体   English

Dotnet Core WebAPI IIS Express 基本 URL

[英]Dotnet Core WebAPI IIS Express base URL

I've got a webapi that runs in production on a Virtual Directory on ISS, end result is something like api.companyname.com/APINAME/我有一个 webapi,它在 ISS 上的虚拟目录上运行,最终结果类似于api.companyname.com/APINAME/

Now I need to be able to locally test the API using either dotnet run or IIS Express with a baseUrl such as the above, the end result would be something like localhost:5555/APINAME/ .现在,我需要能够使用 dotnet run 或带有 baseUrl 的 IIS Express 本地测试 API,如上述,最终结果将类似于localhost:5555/APINAME/

My problem is that I can't change anything in code to have it work and I can't find anything in the web as to where I can go to configure this.我的问题是我无法更改代码中的任何内容以使其正常工作,而且我无法在网络上找到任何关于可以在哪里配置它的信息。 I've tried changing the LaunchSettings.json file as well.我也尝试过更改 LaunchSettings.json 文件。

There are two different things you are trying to achieve.您正在尝试实现两种不同的目标。

To (re)define the listening endpoint(s), you can use the --urls parameter of dotnet the following way:要(重新)定义侦听端点,您可以通过以下方式使用 dotnet 的--urls参数:

dotnet <yourdll.dll> --urls "http://*:5000"

You can also provide more than one endpoint (ie https, ipv6,...)您还可以提供多个端点(即 https、ipv6、...)

Try it out now .立即试用

My guess it, that this is all you need to do, and the App already has the path configured.我猜,这就是你需要做的所有事情,并且应用程序已经配置了路径。 If not, read on.如果没有,请继续阅读。

The other thing is the path base.另一件事是路径基础。 That ("/myapp/") cannot be configured this way.那个 ("/myapp/") 不能以这种方式配置。 To do that, you need to alter the source code.为此,您需要更改源代码。 Best practice is to configure your AppBuilder like that:最佳实践是像这样配置你的 AppBuilder:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        app.UsePathBase(...);
        ....

If you cannot edit the source code, you could wrap your own application around the dll.如果您无法编辑源代码,您可以将自己的应用程序包装在 dll 周围。 But thats going to far to be answered here.但这远没有在这里得到回答。

Please accept as answer when it worked, thank you.请在工作时接受作为答案,谢谢。

Have Fun!玩得开心!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM