python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
mvc 5 web api base controller

MVC 5 Web API Base Controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc.Filters;

namespace myPortal.API
{
    /// <summary>
    /// Base api controller will extend to all apis. And can handle authentication and authorization here.
    /// </summary>
    public class BaseAPIController : ApiController
    {
        /// <summary>
        /// BaseAPIController constructor will check that identity exists or not.
        /// </summary>
        public BaseAPIController()
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    SetHeader();
                }
        }

        /// <summary>
        /// Set header status code to 401
        /// </summary>
        public void SetHeader()
        {
            HttpResponse resp = HttpContext.Current.Response;
            resp.StatusCode = 401;
            resp.End();
        }
    }

}
ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions