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

  • Home
  • SEARCH
  • 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 9210753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:08:55+00:00 2026-06-18T01:08:55+00:00

Hi I’m using FluentSecurity to authenticate and verify users permissions in my MVC application.

  • 0

Hi I’m using FluentSecurity to authenticate and verify users permissions in my MVC application. In the basic settings when a user wants to access to denied Action it throws an exception. I want to know how should I redirect to another page (such as login page) instead of showing yellow exception page ?

  • 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-18T01:08:56+00:00Added an answer on June 18, 2026 at 1:08 am

    I know this question has been answered already but I don’t like putting a try catch in every action to handle this situation.

    Fluent Security allows you to register a handler for policy violations (see https://github.com/kristofferahl/FluentSecurity/wiki/Policy-violation-handlers). You have to have a class that inherits from IPolicyViolationHandler. The convention is to name your class <PolicyViolationName>PolicyViolationHandler

    Here is an example of a Handler to register a DenyAnonymousAccessPolicyViolationHandler

        /// <summary>
        /// Custom Policy Violation Handler. See http://www.fluentsecurity.net/wiki/Policy-violation-handlers
        /// </summary>
        public class DenyAnonymousAccessPolicyViolationHandler : IPolicyViolationHandler
        {
            public ActionResult Handle(PolicyViolationException exception)
            {
                Flash.Error("You must first login to access that page");
                return new RedirectResult("/");
            }
        }
    

    One other caveat that you will run into is that you have to use an IOC container to register these handlers. I won’t debate whether using and IOC container is good or bad but I prefer not to use on if I don’t have too. On their website there was a blog written on how to do this without using an IOC container but I didn’t really like that approach as well. Here is what I did.

    public static class SecurityConfig
        {
            public static void Configure()
            {
                SecurityConfigurator.Configure(c =>
                    {
                        c.GetAuthenticationStatusFrom(() => HttpContext.Current.User.Identity.IsAuthenticated);
                        c.GetRolesFrom(() => (HttpContext.Current.Session["Roles"] as string[]));
                            // Blanked Deny All
                        c.ForAllControllers().DenyAnonymousAccess();
    
                        // Publicly Accessible Areas
                        c.For<LoginController>().Ignore();
    
                        // This is the part for finding all of the classes that inherit
                        // from IPolicyViolationHandler so you don't have to use an IOC
                        // Container.
                        c.ResolveServicesUsing(type =>
                            {
                                if (type == typeof (IPolicyViolationHandler))
                                {
                                    var types = Assembly
                                        .GetAssembly(typeof(MvcApplication))
                                        .GetTypes()
                                        .Where(x => typeof(IPolicyViolationHandler).IsAssignableFrom(x)).ToList();
    
                                    var handlers = types.Select(t => Activator.CreateInstance(t) as IPolicyViolationHandler).ToList();
    
                                    return handlers;
                                }
                                return Enumerable.Empty<object>();
                            });
                    });
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am using JSon response to parse title,date content and thumbnail images and place
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.