0

I did redirect to external link in asp.net core in local

public async Task<IActionResult> Fallback(string transactionId, [FromForm] FallbackRequest fallbackRequest)
{
    var result = await _opayoPaymentService.FallbackRequest(transactionId, fallbackRequest);
    return Redirect($"http://localhost:4200/payment-done/{transactionId}/{result.Status}");
}

http://localhost:4200/ this is local on local environment (Angular project).

Now, the Angular project is on production. The url is http://production-url/

Now I want to redirect the production url.

How can I add both urls? When the project runs in production, then production url should be redirected, when the project runs locally, then localhost url should be redirected.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
hanushic
  • 369
  • 1
  • 5
  • 19

1 Answers1

0

Your description reminded me the appsetting.json and appsetting.development.json, you can set your url as a variable in the configuration file and use it in your code rather than hard-coding the url into your code. Here's a high vote answer based on this scenario, it also provides some related documents in it.

enter image description here

What I wanna add here is some other ways. First, you can also define the url as a variable, which obtain the value from the server's environment variable, it requires you to set an environment variable before deploy your application.

Another way is storing the url into your database and create a management website to modify the value if it needs to be changed. This method is suitable for those application which already has some management page or is about to design management module for the whole application. The advantage is really flexible and easy to change, such as the web url is changed due to some reason so your app need to change the url corresponding to it. As you know some application really needs to do much configuration when it's running.

Tiny Wang
  • 10,423
  • 1
  • 11
  • 29