I am new to web api and I seem to have a problem getting the name of the signed user inside my mail method. I use
RequestContext.Principal.Identity.Name
However, it seems that this only returns an empty string. It works fine in my get method, but not in the message. Here is my method
[Route("receive")] [HttpPost] public HttpResponseMessage Receive(PostmarkInboundMessage message) { if (message != null) { // To access message data var headers = message.Headers ?? new List<Header>(); // To access Attachments if (message.Attachments != null) { var attachments = message.Attachments; var c = new CVService(); var user = string.IsNullOrEmpty(RequestContext.Principal.Identity.Name) ? "unknown" : RequestContext.Principal.Identity.Name; c.UpdateLog(user); foreach (var attachment in attachments) { // Access normal members, etc var attachmentName = attachment.Name; // To access file data and save to c:\temp\ //if (Convert.ToInt32(attachment.ContentLength) > 0) //{ // byte[] filebytes = Convert.FromBase64String(attachment.Content); // var fs = new FileStream(attachmentSaveFolder + attachment.Name, // FileMode.CreateNew, // FileAccess.Write, // FileShare.None); // fs.Write(filebytes, 0, filebytes.Length); // fs.Close(); //} } } // If we succesfully received a hook, let the call know return new HttpResponseMessage(HttpStatusCode.Created); // 201 Created } else { // If our message was null, we throw an exception throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent("Error parsing Inbound Message.") }); } }
Any help would be greatly appreciated.
source share