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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:10:52+00:00 2026-05-14T02:10:52+00:00

Greetings, in my asp.net mvc application what i would like to do is to

  • 0

Greetings,
in my asp.net mvc application what i would like to do is to enable access to some pages only after user was successfully authorized. I have already created custom membership provider and that works fine. How can I, in web config create such rule – for instance for all pages in ~Admin/ folder? I don’t want to create on every controller’s action the validation code.
For now i have in my web.config the following statement:

    <location path="~/Admin"> 
<system.web>
  <authorization>
    <deny users="?"/> 
  </authorization>
</system.web>

but it doesn’t work.

  • 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-14T02:10:53+00:00Added an answer on May 14, 2026 at 2:10 am

    Doing authorization logic in config files has one big disadvantage: it cannot be easily unit tested, and something so important as authentication should be unit tested. I would recommend you for this matter to write a custom authorization filter which could be used to decorate a base controller for all admin actions that requires authentication:

    [AttributeUsage(
        AttributeTargets.Method | AttributeTargets.Class, 
        Inherited = true
    )]
    public class RequiresAuthenticationAttribute 
        : FilterAttribute, IAuthorizationFilter
    {
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
            {
                filterContext.Result = new RedirectResult(
                    string.Format("{0}?ReturnUrl={1}", 
                        FormsAuthentication.LoginUrl, 
                        filterContext.HttpContext.Request.Url.AbsoluteUri
                    )
                );
            }
        }
    }
    

    And your admin controller:

    [RequiresAuthentication]
    public class AdminController : Controller
    {
        // .. some actions that require authorized access
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings, I have an asp.net mvc application. I have some links that corresponds to
Greetings, in my asp.net mvc application I have a listbox rendered as follows: <%=
Greetings, The question relates to ASP.NET MVC I am creating some divs dynamically using
Greetings! I'm doing a Form on ASP.NET MVC 2, in my view I have
Greetings, I would like to use EF4 but I only have Visual studio 2010
Greetings! I am developing Asp.net application, in which i need to use sqlite as
Greetings! I'm new to WCF and I thought it would be similar to ASP.NET
I'm facing a very strange problem in my ASP.NET Application. When the user clicks
Greetings folks, The ASP.NET application I'm maintaining has a fairly long start up procedure.
Greetings, I have asp.net check box control and asp.net dropdownlist control inside div tag.

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.