rahul patil

rahul patil

  • NA
  • 160
  • 7.7k

how to create a token and then after authorize person access

Jun 14 2020 12:53 AM
now when I click on the send button of postman then direct access the index method that is issue I want to generate a token and then after authorize person access that method
 
 
 
 staticvariable.cs
  1. public static class staticvariable  
  2.  {  
  3.      public static HttpClient webapiclient = new HttpClient();  
  4.   
  5.      static staticvariable()  
  6.      {  
  7.          webapiclient.BaseAddress = new Uri("http://localhost:5718/api/");  
  8.          webapiclient.DefaultRequestHeaders.Clear();  
  9.          webapiclient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));  
  10.      }  
  11.  }  
studController.cs
  1. public class studController : Controller    
  2. {    
  3.      // GET: Home    
  4.      public JsonResult Index()    
  5.      {    
  6.          IEnumerable<student> studlist;    
  7.          HttpResponseMessage response = staticvariable.webapiclient.GetAsync("stud").Result;    
  8.          studlist = response.Content.ReadAsAsync<IEnumerable<student>>().Result;    
  9.          return Json(studlist,JsonRequestBehavior.AllowGet);    
  10.      }    
  11. }  
what i want to the
when click on the send button of the postman then after generate the token means authoriz person can access that index method
 
help? 

Answers (1)