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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:35:47+00:00 2026-06-03T18:35:47+00:00

I’m working on a system that needs to know a user’s choice before they

  • 0

I’m working on a system that needs to know a user’s choice before they enter a site. Up till now the choice has been stored in a cookie and checked by JavaScript on the page load – if the cookie doesn’t exist then a dialog is shown and the user makes the choice.

Although we’d normally expect the user to arrive at the homepage of the application, they can legally follow a URL to any page within the application, so the JavaScript to check the choice exists on every page.

This has caused problems (almost always fixed by clearing cookies) so we’re switching to store the choice in the database. What we need is a neat way of making sure that all pages (MVC and Web Forms) check that the choice has been made and, if it hasn’t, either display a dialog or redirect to a page where the choice can be made.

The main thing bothering me is that to cause a redirect using MVC, I need to return a RedirectResult, and this can only be done from an Action. I don’t want every action to have code regarding this check – it seems like the kind of thing that should be possible from a base controller (in the same way a base page could cause a Response.Redirect.

Can anyone suggest a good way for all pages to perform a check on the database and then either cause a redirect or show a dialog?

  • 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-06-03T18:35:50+00:00Added an answer on June 3, 2026 at 6:35 pm

    The main thing bothering me is that to cause a redirect using MVC, I
    need to return a RedirectResult, and this can only be done from an
    Action.

    Oh not at all. You could also redirect from a custom action filters.

    For example you could write a custom IAuthorizationFilter that will check whether the user made the necessary choice and if not redirect to some given page. The check could be done against a cookie, database or wherever you decide to persist this information:

    public class EnsureChoiceHasBeenMadeAttribute : FilterAttribute, IAuthorizationFilter
    {
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            // get the current user
            var user = filterContext.HttpContext.User;
            if (user.Identity.IsAuthenticated && !UserMadeAChoice(user.Identity.Name))
            {
                // if the current user is authenticated and he didn't made a choice
                // redirect him to some page without even attempting to execute
                // the controller action that he requested
                var values = new RouteValueDictionary(new
                {
                    controller = "home",
                    action = "index"
                });
                filterContext.Result = new RedirectToRouteResult(values);
            }
        }
    
        private bool UserMadeAChoice(string username)
        {
            throw new NotImplementedException();
        }
    }
    

    Now you have different possibilities:

    • You decorate the controllers/actions that you want to perform this check with the [EnsureChoiceHasBeenMade] attribute
    • You register the action filter as a global action filter so that it applies to absolutely all actions
    • You write a custom filter provider in order to dynamically apply the action filter to some actions based on some dynamic values (you have access to the HttpContext).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.