2

I can't believe I cannot find any solution to this. For business reason, RedirectToAction or anything won't do because it causes a HTTP 302 to be returned. An example:

public async Task<IActionResult> GoogleLoginCallback(GoogleLoginCallbackViewModel requestModel) { if (requestModel == null || !requestModel.Error.IsNullOrEmpty()) { // Return something here // to process at Login Action instead // maybe with Error data passed } // Normal processing } 

The nearest I can find is this post using TransferResult but:

  1. It seems ugly to me.
  2. Does not work for ASP.NET Core.

Is there anyway to transfer the request to another Route/Action without returning a HTTP Redirection?

8
  • You should be able to rewrite it, learn.microsoft.com/en-us/aspnet/core/fundamentals/… Commented Oct 6, 2018 at 18:59
  • 2
    If it's in the same controller, simply call the other method directly and return its result. If it's in another controller, see stackoverflow.com/q/16870413/11683. Commented Oct 7, 2018 at 7:59
  • @GSerg yeah I think that is the best way for now. (Note: for .NET Core, I use manual Service Provider from this post: stackoverflow.com/questions/32459670/…) Commented Oct 7, 2018 at 10:48
  • Why do you not want to redirect? That's how it should be done. Commented Oct 8, 2018 at 13:57
  • 2
    Well, not redirecting can have numerous side effects. Since you're essentially returning the same thing another route does at a different route, you can end up with duplicate content penalties from search engines. Additionally, if you have form which does a postback (as is typical), it will post to the URL it was server under, not where it actually needs to go, which can cause things to break dramatically. Sometimes requirements don't make sense. It's your job as a developer to call out such instances as much as it is to implement the requirements. Commented Oct 8, 2018 at 15:39

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.