Я пытался протестировать свои API (Direct Download Pdf API), используя почтальон (Send & Download), и все прошло успешно, файл был успешно загружен, нет необходимости устанавливать регистрационную информацию . Но когда я попытался использовать браузер Mozilla , он сказал мне требуется вход? почему?
Вот мой заголовок ответа с использованием почтальона:
И здесь, когда я пытаюсь использовать браузер, покажите загрузчику idm запрос имени пользователя пароль:
Вот мой код
[Authorize]
[HttpGet]
public IHttpActionResult GetDownloadPdf(string date)
{
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
ResponseData responseData = new ResponseData();
try
{
_logDataBLL.SaveRequestLogRecord(RequestType.GET, MethodBase.GetCurrentMethod().Name);
MA_MS_Agent objdata = new MA_MS_Agent();
//Update - Checking current user still active
var identity = User.Identity as ClaimsIdentity;
if (LoginBLL.isStillActive(identity) == false)
{
dynamic Reject = new ExpandoObject();
Reject.Message = "Authorization has been denied for this request.";
return Content(HttpStatusCode.Unauthorized, Reject);
}
date = "01" + date.Substring(2);
string filename = "1000007"+ "_" + date + ".pdf";
ByteArrayContent pdfByte;
MA_MS_ApplicationParameter Selected_Parameter = AddReferralBLL.getAppParameterByCode("APPP025");
string param_value = Selected_Parameter.ApplicationParameter_Value;
string pdfFilePath = param_value + filename;
byte[] bytes = null;
if (File.Exists(pdfFilePath))
{
bytes = System.IO.File.ReadAllBytes(pdfFilePath);
}
else
{
return BadRequest();
}
using (var m = new MemoryStream())
{
pdfByte = new ByteArrayContent(bytes);
}
if (pdfByte == null)
{
responseData = _responseDataBLL.GenerateResponseData(HttpStatusCode.NoContent);
responseData.status = true;
return Ok(responseData);
}
response.Content = pdfByte;
response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = filename;
response.Content.Headers.ContentType = new MediaTypeHeaderValue("Application/pdf");
//response.Headers.Add("MyHeader", "MyHeaderValue");
//response.Content = new StringContent(JsonConvert.SerializeObject(result), Encoding.UTF8, "application/json");
return ResponseMessage(response);
}
catch (Exception ex)
{
string error = ex.Message;
if (ex.InnerException != null)
error += " => " + ex.InnerException.Message;
responseData = _responseDataBLL.GenerateResponseData(HttpStatusCode.InternalServerError, error);
_logDataBLL.SaveResponseLogRecord(JsonConvert.SerializeObject(responseData));
return Content(HttpStatusCode.InternalServerError, responseData);
}
}