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 6784715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:01:51+00:00 2026-05-26T17:01:51+00:00

I have the following in my code: if (Session[CurrentUrl] != null) { var ip

  • 0

I have the following in my code:

if (Session["CurrentUrl"] != null) 
{
    var ip = new Uri((string)Session["CurrentUrl"]);
    var ipNoPort = string.Format("{0}://{1}/{2}", ip.Scheme, ip.Host, ip.PathAndQuery);
    return Redirect(ipNoPort);
}

return Home();

It checks if a Session variable is set and then redirects to that URL or lets the action return to the Home method.
Does anyone have an example of how I could convert this into an action filter?
Also can I provide the action filter with the parameter of “Home” so it knows where to go to next?

  • 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-26T17:01:52+00:00Added an answer on May 26, 2026 at 5:01 pm

    Here is an example for ActionFilter that does redirect

    public class TheFilter: ActionFilterAttribute
    {
       public override void OnActionExecuted(ActionExecutedContext filterContext)
       {
           var controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
           if (controllerName !="TopSecert")
                return;
    
           var redirectTarget = new RouteValueDictionary
                     {{"action", "ActionName"}, {"controller", "ControllerName"}};
    
           filterContext.Result = new RedirectToRouteResult(redirectTarget);
           // Or give a url (the last in this example):
           filterContext = new RedirectResult(filterContext.HttpContext.Request.UrlReferrer.AbsolutePath);
           // The session you can get from the context like that:
           var session = filterContext.HttpContext.Session;
       }
    }
    

    Edit: change from Executing to Executed and added session handling.

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

Sidebar

Related Questions

I have the following code: var redirectIp = string.Format({0}{1}, Session[CurrentHost], ip.PathAndQuery); return new RedirectResult(redirectIp);
I have the following code: if (Session[CurrentUrl] != null & Session[CurrentHost] != null) I
I have the following code: public static string FormatHostAndUrl(this HttpSessionStateBase session) { var a
I have the following code factory = new Configuration().Configure().BuildSessionFactory(); session = factory.OpenSession(); var query
I have the following code segment in which I'm getting error using (var session
i have the following code using Nhibernate.Linq var apps = Session.Linq<History>().OrderByDescending(r => r.LastUpdated).Take(50); Console.Write(apps.Count());
Inside my user object I have the following code to generate a new 'session'
I have the following code. <s:push value=#session['person']> <s:if test=%{admin=='y'}> <a class=add href=/projit1/project/addProject.jsp>Create a Project</a>
I have following code class User attr_accessor :name end u = User.new u.name =
I have the following code: new MapMaker().expireAfterAccess(SESSION_EXPIRATION, TimeUnit.MILLISECONDS).makeMap(); In guava 10 it said it

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.