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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:48:24+00:00 2026-06-10T01:48:24+00:00

I have an ASP.NET MVC based application that allows different levels of access depending

  • 0

I have an ASP.NET MVC based application that allows different levels of access depending on the user. The way it currently works is when a user accesses a page, a check is done against the database to determine the rights that user has. The view is then selected based on the level of access that user has. Some users see more data and have more functionality available to them than do others. Each page also makes a variety of ajax calls to display and update the data displayed on the page.

My question is what is the best way to ensure that a particular ajax call originated from the view and was not crafted manually to return or update data the user does not have access to? I would prefer not to have to go to the database to re-check every time an ajax call is made since that was already done when the user initially loaded the 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-10T01:48:26+00:00Added an answer on June 10, 2026 at 1:48 am

    Check out the Authorize Attribute, you can put it on an entire controller or just specific methods within your controller.

    Examples:

    [Authorize(Roles = "Administrator")]
    public class AdminController : Controller
    {
     //your code here
    }
    

    or

    public class AdminController : Controller
    {
        //Available to everyone
        public ActionResult Index()
        {
            return View();
        }
    
        //Just available to users in the Administrator role.
        [Authorize(Roles = "Administrator")]
        public ActionResult AdminOnlyIndex()
        {
            return View();
        }
    }
    

    Alternately, you can write a custom Authorize attribute to provide your own logic.

    public class CustomAuthorizeAttribute : AuthorizeAttribute 
    {           
        protected override bool AuthorizeCore(HttpContextBase httpContext)     
        {
            IPrincipal user = httpContext.User;     
            var validRoles = Roles.Split(',');//Roles will be a parameter when you use the Attribute        
            List<String> userRoles = GetRolesFromDb(user);//This will be a call to your database to get the roles the user is in.
    
            return validRoles.Intersect(userRoles).Any();
        }
    } 
    

    To use:

     [CustomAuthorizeAttribute(Roles = "Admin,Superuser")] 
     public class AdminController : Controller {
    
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a web based (ASP.NET MVC) application that uses SQL Server 2008 for
We have a ASP.NET MVC 3 application that uses unobtrusive jQuery validation. The page
I have a Regex based whitespace filter on an ASP.NET MVC application, and it
I have an ASP.NET MVC Web Application that interacts with a SQL Server 2008
I am developing an application which is web-based (asp.net MVC). The user configures reminders
We have an ASP.NET MVC 4 application that links to legacy native code. The
I have an existing ASP.NET MVC 2 application that I've been asked to extend.
I have an ASP.NET MVC application with a page that displays a large table
Hi I am developing a simple application based upon ASP.NET MVC. I have altered
We have an ASP.NET application that's partly in MVC (the rest of it being

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.