简体   繁体   English

如何为ASP Net Core应用程序定义api地址

[英]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.

相关问题 必须如何将地址写入api控制器以及控制器中的属性。 ASP.NET核心 - How must be write adress to api controller and with attribute in controller. ASP.NET Core 如何在 Asp.Net Core MVC 项目中为 Swagger 文档显式定义 API 控制器路径 - How to explicitly define API Controllers Path for Swagger documentation in Asp.Net Core MVC Project 如何从 ASP.NET Core 应用程序将应用程序洞察数据发布到 REST API 而不是 Azure? - How to post application insights data to REST API instead of Azure from ASP.NET Core application? 如何在asp.net core的方法中将var定义为全局变量 - How to define var as global variable in the method in asp.net core 如何在ASP.NET Core中定义和使用不同的用户类型 - How to Define and use Different User Types in ASP.NET Core 如何为 asp.net 核心应用程序定义基础 url - How to define the base url for the asp.net core app 如何在 ASP.NET Core 中定义、引发和处理异步事件 - How to define, raise and handle async events in ASP NET Core 处理身份验证/授权:ASP.NET Core Web 应用程序 => ASP.NET Core Web API => SQL - Handling authentication/authorization: ASP.NET Core Web Application => ASP.NET Core Web API => SQL 如何在ASP.Net Core 2.2 Web Api应用程序中连接到Amazon Kinesis Firehose - How to connect to Amazon Kinesis Firehose in ASP.Net Core 2.2 Web Api Application 如何在ASP.NET Core 6.0 Web API中读取Azure App服务的应用设置 - How to read application setting of Azure App service in ASP.NET Core 6.0 Web API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM