This below code works perfectly fine on local test IIS express server, it will return http code 401. however when deployed to linux server, the response is 200 with data without any authorization header.
public async Task<object> Any(QueryMerchantCustomers qry)
{
// logging
try
{
var json = JsonConvert.SerializeObject(Request.Authorization);
var filePath = Path.Combine(Directory.GetCurrentDirectory(), $"{Guid.NewGuid()}.json");
await System.IO.File.WriteAllTextAsync(filePath, json);
}
catch (Exception ex)
{
// Handle any errors that may occur while writing the file
Log.Error(ex, "Failed to write txn to local file.");
}
if (!_authHandler.VerifyJwt(Request, out var claimsPrincipal, "user", qry.MerchantGuid) && !base.Request.IsLocal)
{
//throw new HttpError(HttpStatusCode.Unauthorized, "Unauthorized");
base.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
base.Response.EndRequest();
}
var res = new QueryResponse<Customer>();
var customers = new List<Customer>();
if (string.IsNullOrEmpty(qry.MerchantGuid))
return res.AddError("Merchant guid can not be null or empty");
var merchant = await _jointMerchantHandler.GetMerchantByGuidAsync(qry.MerchantGuid);
// make it re-usable in future
if (qry.Page > 0 && qry.Limit > 0)
{
qry.Page -= 1;
qry.Skip = qry.Page * qry.Limit;
qry.Take = qry.Limit;
}
var q = AutoQuery.CreateQuery(qry, base.Request);
q.And<UserDetail>(x => x.LicenseId == merchant.PrimaryLicenseId && !x.IsDelete);
var result = AutoQuery.Execute(qry, q);
if (result.Results.Count == 0) return res;
var details = _userDetailRepo.Select(x => x.LicenseId == merchant.PrimaryLicenseId && Sql.In(x.UserId, result.Results.Select(x => x.Id).ToList()));
foreach (var user in result.Results)
customers.Add(user.ToCustomer().MergeDetail(details.FirstOrDefault(x => x.UserId == user.Id && !x.IsDelete)));
res.ResponseStatus = result.ResponseStatus;
res.Meta = result.Meta;
res.Offset = result.Offset;
res.Total = result.Total;
res.Results = customers;
base.Response.AddHeader("x-aq-sql", System.Text.RegularExpressions.Regex.Escape(q.ToMergedParamsSelectStatement()));
return res;
}
Yes. but on linux, base.Response.EndRequest(); doesn’t end. I tried throw new HttpError(HttpStatusCode.Unauthorized, “Unauthorized”);, it is also not working. I am referring to this docs Customize HTTP Responses · stulife/ServiceStack Wiki · GitHub