Created
March 8, 2017 11:38
-
-
Save birksy89/b8423cc027b7d9d9b0ffc542c3758172 to your computer and use it in GitHub Desktop.
Return JSON - DNN Web API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[AllowAnonymous] | |
[HttpGet] | |
public HttpResponseMessage GetAllMessages() | |
{ | |
try | |
{ | |
//Load Data Into List | |
var mm = new MessageManager(); | |
List<Message> msgs = mm.GetAllMessages(); | |
//Convert List Into JSON | |
var jsonmsgs = JsonConvert.SerializeObject(msgs); | |
//Create a HTTP response - Set to OK | |
var res = Request.CreateResponse(HttpStatusCode.OK); | |
//Set the content of the response to be JSON Format | |
res.Content = new StringContent(jsonmsgs, System.Text.Encoding.UTF8, "application/json"); | |
//Return the Response | |
return res; | |
} | |
catch (Exception exc) | |
{ | |
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
THANK YOU!!! Good Lord I spent way too much time on this.