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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:31:46+00:00 2026-06-03T09:31:46+00:00

We are planning on using ASP.Net MVC3 to create a JSON API. For handling

  • 0

We are planning on using ASP.Net MVC3 to create a JSON API. For handling security we will have something like an API key, or possibly the Username/Password and maybe a timestamp.
I haven’t done any MVC before but I’m wondering if there isn’t some simple way to add code to Global.asax that ensures that ALL requests have these variables in them somehow. That way, no request could even get through unless it included the API key.
That way we don’t have to add API key handling to each section of the site.

  • 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-03T09:31:47+00:00Added an answer on June 3, 2026 at 9:31 am

    Create a global authorization filter –

    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
    public class MyAuthorizationFilterAttribute : FilterAttribute, IAuthorizationFilter
    {
        public void OnAuthorization(AuthorizationContext filterContext)
        {
        // do Authorization
        }
    }
    

    then register it in Global.asax –

    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new MyAuthorizationFilterAttribute());
        }
    protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
    
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    

    Although you could create a bespoke Authentication module –

    public class CustomAuthentication : IHttpModule
    {
        public void Init(HttpApplication application)
        {
            application.AuthenticateRequest += new EventHandler(this.Authenticate);
        }
        public void Authenticate(object source, EventArgs eventArgs)
        {
            HttpApplication _application = (HttpApplication)source;
            HttpContext _context = _application.Context;
    
            // do authentication
    
            // if authenticated set pricipal
            // _context.User = new GenericPrincipal(new GenericIdentity("user"), new string[]);
    
        }
    
    
        public void Dispose() { }
    }
    

    Then you just need to register the module in web.config

    <modules runAllManagedModulesForAllRequests="true">
          <add name="CustomAuthentication" type="AuthenticationNamespace.CustomAuthentication"/>
    </modules>
    

    and set asp.net authentication to none –

    <authentication mode="None">
    </authentication>
    

    Then you can check to see it the user is authenticated in your AuthorizationFilter.

    if(HttpContext.Current.Request.User.Identity.IsAuthenticated)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an intranet system developed using asp.net webforms. We are kind of planning
We are using Asp.Net 2.0 and planning to move to TDD so that middle
I'm planning to design simple website using ASP.NET MVC new technology. Many concepts are
I'm planning on using MEF within ASP.NET looking for some insight into thread safety
I will soon need to add SSO to an ASP.NET app using SAML. The
I am using Asp.net/C# in my project , i have a requirement where in
I would like to start with integration testing. I am using an ASP.NET MVC
I am using asp.net mvc and have a section where a user can upload
I'm planning on creating a browser based RTS game using ASP.NET and MySQL. I
I am currently using ASP.NET MVC1 in my project but now i am planing

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.