How can I get the browser from the IOwinContext?
I am attempting to log requests alongside their responses from my owin middleware (code below).
public async override Task Invoke(IOwinContext context)
{
var sw = new Stopwatch();
sw.Start();
var user = context.Authentication.User.Identity.IsAuthenticated ?
context.Authentication.User.Identity.Name :
"anonymous";
_logger.WriteVerbose(
string.Format("{0} {1} '{2}{3}{4}' @ {5} for {6}",
context.Request.Scheme,
context.Request.Method,
context.Request.PathBase,
context.Request.Path,
context.Request.QueryString,
context.Request.LocalIpAddress,
user));
await Next.Invoke(context);
_logger.WriteVerbose(
string.Format("{0} {1} {2}ms - {3}",
context.Response.StatusCode,
context.Request.Path,
sw.ElapsedMilliseconds,
context.Request.Browser); //???
}
You can obtain the User-Agent header from the request:
context.Request.Headers.Get("User-Agent")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With