Hi,
In my MVC application I want to redirect to an aspx page from an api controller. I tried adding the code but its not working. Can someone please check it and help me to fix the issue.
api controller:

Action Method in Home controller

Hi,
In my MVC application I want to redirect to an aspx page from an api controller. I tried adding the code but its not working. Can someone please check it and help me to fix the issue.
api controller:

Action Method in Home controller

Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Naimish MakwanaRank #324 · 7.7K reputationPosted Jan 17, 2023, 5:43 AM EST
Please try the below solution.
public HttpResponseMessage GetMethod() { // now redirect var response = Request.CreateResponse(HttpStatusCode.Moved); response.Headers.Location = new Uri(); //EX : "http://www.google.com" return response; }Or refer below link. That will help you.
https://stackoverflow.com/questions/33548370/redirect-from-apicontroller-action-to-other-mvc-controller-action
Thanks.
Pasang TamangRank #449 · 5.6K reputationPosted Jan 17, 2023, 5:53 AM EST
Hi,
In real scenario, redirect to page from API is not recommended. API are more focus to make communication between your UI and backend part. You can follow as suggested by @Naimish Makwana. Another way is You can return the URL that you want to redirect. When you consume the API you will get URL in response and you make a redirection to the URL you get from response.
Just an example, below code will return URL as response. Client app will catch this URL and make a redirection in client app.
[HttpGet("{id}")] public string Get(int id) { //your logical code here return "https://www.google.com"; }I hope this will make sense to you :)
Regards,
Pasang