How to do redirect instead of response to Get method

Igor Cova

I have a Get method

[Route("login/{code}")]
public class LoginController : Controller {
  [HttpGet]
  public void Login(string code) {
    bool resp = TryToLogin(code);

    if (resp == true) {
      redirectToSiteOne;
    } else {
      redirectToSiteTwo;
    }
  }
}

And I don't understand how to make redirect to another site (there is must be redirect from api.example.com to example.com maybe it's important)

Abhishek Jaiswal

I found 2 methods to do that :

Method 1 - change void return type to HttpResponseMessage

var res = Request.CreateResponse(HttpStatusCode.Moved);
res.Headers.Location = new Uri("https://www.google.com");
return response;

Method 2 - change void return type to RedirectResult

return RedirectPermanent("https://www.google.com");

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Response.Redirect with POST instead of Get?

How to get a hold of the first HTTP (redirect) response?

How to get response field as json instead of string?

Redirect using get and then redirect to the response

Redirect using get and then redirect to the response

How to fetch json response instead of html response from a get request?

How do I pass a req.setHeaders method on res.redirect method within the same app.get function?

How do I Mock a method that makes multiple POST and GET request all requiring different response data?

How do I get with a xpath method a number instead of text in the Scrapy output file?

How do you redirect wget response to standard out?

How do you redirect to a page when the response keeps returning in JSON?

Python Requests : How to get response cookie from 302 redirect

How do I make my redirect include the name instead of an ID?

how to get the redirect url instead of page content in golang?

How do I get the redirect url?

Why ExceptionHandlerExceptionResolver makes redirect instead of simple response?

Returning redirect response instead of expected leaf view

How to make $http.get return response instead of promise object?

How to get just an entity id instead of the entire entity in JSON response

How to get youtube API 3 response as XML instead of JSON?

How to get the response from post request in array instead of object in laravel

How to get full response instead of just body using await in reactJS

How do I get a response from this website?

How do I get a users response in Dialogflow

How do I get a users response in Lambda

How do i get the response from prompt

How do I get [] instead of {} in an array in javascript

Android retrofit response body, jwt in response, how do to get it?

How to get named json response Flutter using http get method