Skip to main content

Posts

Showing posts with the label #MVC

#MVC #API Create and Read custom header.

Website In EmespmdHttpClient class add public void SetUserIdentifier( string userIdentifier)         {             this .DefaultRequestHeaders.Add( "EMESPMD-USER" , userIdentifier);         } From action method send _loggedInUser.XomPersonnelId as a separate param(naming userIdentifier) to each service call. In Gateway service add below line next to try{        _emespmdHttpClient.SetUserIdentifier(userIdentifier); Service Create an extension( HttpRequestExtensions ) method in EMESPMD.Api.MessageHandler folder. public static class HttpRequestExtensions     {         public static string RequestedUserIdentifier( this HttpRequestMessage request)         {         ...

#MVC Authorize Attribute

Authorization is the process of determining the rights of an authenticated user for accessing the application's resources. The Asp.Net MVC Framework has a AuthorizeAttribute filter for filtering the authorized user to access a resource. Authorize Attribute Properties Properties Description Roles Gets or sets the roles required to access the controller or action method. Users Gets or sets the user names required to access the controller or action method. Filtering Users by Users Property Suppose you want to allow the access of AdminProfile to only shailendra and mohan users then you can specify the authorize users list to Users property as shown below. [ Authorize ( Users = "Raj,Deena,Siva,Gow" )] public ActionResult AdminProfile () { return View (); } Filtering Users by Roles Property Suppose you want to allow the access of AdminProfile action to only Admin and SubAdmin roles then you can specify the authorize roles...