Getting Error in PhysicalApplicationPath

Case 1

Let's see the code shown in the following: 

  1. string rootPath = ConfigurationManager.AppSettings["FilePath"];  
  2. var currentApplicationPath = HttpContext.Current.Request.PhysicalApplicationPath;  
  3. var provider = new MultipartFormDataStreamProvider(currentApplicationPath + "\\tempUploads");  
  4. try{  
  5.   
  6.      await Request.Content.ReadAsMultipartAsync(provider);  
  7.   
  8.    }  
  9. catch(Exception ex)  
  10.     
  11. {  
  12.   
  13.    throw ex;  
  14.   
  15. }  

Here i am passing from header Accept: tex/json.

I am getting error. with used above code, error shown in the following screenshot:

 

Case 2

If I used MultipartFormDataStreamProvider with app ConfigurationManager.AppSettings["FilePath"] than I was successfully execute my code.

  1. string rootPath = ConfigurationManager.AppSettings["FilePath"];  
  2. var provider = new MultipartFormDataStreamProvider(ConfigurationManager.AppSettings["FilePath"])  
  3.   
  4. try{  
  5.   
  6.     await Request.Content.ReadAsMultipartAsync(provider);  
  7.   
  8. }  
  9. catch(Exception ex)  
  10.   
  11. {  
  12.   
  13.    throw ex;  
  14.