[英]How to define an api adress for an asp net core application
I have an ASP.Net Core application and I would like to use a REST API that I have created. 我有一个ASP.Net Core应用程序,我想使用我创建的REST API。 Do you know a proper way to pass the adress of my API to my controllers ?
您知道将我的API地址传递给控制器的正确方法吗? I can create an Interface with my connection string for my controllers but I would like to know there is a way to use the startup file for example.
我可以使用控制器的连接字符串创建一个Interface,但是我想知道有一种使用启动文件的方法。
Thanks JN but that's not really what I was looking for (or maybe I don't understand you answer). 感谢JN,但这并不是我真正想要的(或者我可能不明白您的回答)。 What I would like to do is to pass a connection string to all my controllers in my application.
我想做的是将连接字符串传递给应用程序中的所有控制器。
For example I have 5 controllers which will connect to my API and call differents controllers in this API. 例如,我有5个控制器,它们将连接到我的API并在此API中调用differents控制器。 At the moment, the adress of my API is something like localhost:56000 but when I will put this on a server, I will have to modify all the adresses in every controllers.
目前,我的API地址类似于localhost:56000,但是当我将其放在服务器上时,我将不得不修改每个控制器中的所有地址。 Do you think that I can pass a string in the constructor of every controller ?
您认为我可以在每个控制器的构造函数中传递字符串吗? But if there isn't a better solution, I will create an Interface I think.
但是,如果没有更好的解决方案,我将创建一个我认为的接口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.