Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 407143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:33:56+00:00 2026-05-12T17:33:56+00:00

Is there a way to inject the referrer action from an action filter? Lets

  • 0

Is there a way to inject the referrer action from an action filter?
Lets say I have a view that comes from action X. In dies view I call action Y and I want to redirect again to action X. (There are multiple X actions that call action Y). I thought that it could be nice if I had a parameter call referrerAction and an action filter that filled it with the previous action. Is it possible?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:33:56+00:00Added an answer on May 12, 2026 at 5:33 pm

    Here’s how I do:

      public class ReturnPointAttribute : Attribute
      {
      }
    
      public class BaseController: Controller
      {
          private string returnPointUrl = null;
          protected override void OnActionExecuted(ActionExecutedContext filterContext)
          {
             base.OnActionExecuted(filterContext);
             if (filterContext.ActionDescriptor.IsDefined(typeof(ReturnPointAttribute), true))
                returnPointUrl = filterContext.HttpContext.Request.Url.ToString();
          }
          public ActionResult RedirectOrReturn<T>(Expression<Action<T>> action) where T : BaseController
          {
             return returnPointUrl.IsNullOrEmpty() 
                ? MyControllerExtensions.RedirectToAction(this, action) 
                : (ActionResult)Redirect(returnPointUrl);
          }
       }
    

    Now, you mark you X actions with [ReturnPoint] and call RedirectOrReturn() if you want to return back.

    I do not use UrlReferrer because it can be wrong and I have no control over its value. With ReturnPoint, you can also have groups, e.g. [ReturnPoint(“Orders”)] and RedirectOrReturn(“Orders”).

    Of course, you can have more automatic behaviour in OnActionExecuted – e.g. it can check if returned result is Redirect, and automatically go to ReturnPoint if it has value. Or you can control this with [ReturnPoint(Automatic=true)], and so on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there some simple way to inject Properties class loaded with a file from
I have a page layout that intherits from PublishingLayoutPage . In it there is
Is there a way to inject EJB 3 stateless session beans into struts 2
Is there any way we can inject new methods and properties into classes during
is there way how to get name ov event from Lambda expression like with
Is there a way to detect via JavaScript (client side) any AJAX requests that
Is there a way to inject the Unity container into an attribute in ASP.NET
Is there any way to inject null value on properties which references undefined beans?
There is a certain page (say, named TargetPage.html in which I inject the Javascript
is there a way to use dependency injection in a widget, that is created

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.