I am making a Web API backend which needs to return the current logged in user's name and it's role. While this works, the problem is that my return Ok("some string") function returns something like this:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Current user: MyUser Role: MyRole</string>
Here is my code:
[ResponseType(typeof(string))]
public IHttpActionResult GetCurrentUser()
{
if (User.Identity.IsAuthenticated)
{
string role = service.GetRole(User.Identity.Name);
if (role != null)
{
return Ok("Current user: " + User.Identity.Name + " " + "Role: " + role);
}
else
{
return Ok("Current user: " + User.Identity.Name + " " + "Role: " + "No role assigned");
}
}
else
{
return BadRequest("Not authenticated");
}
}
How can I make this return just
Current user: MyUser Role: MyRole ?