Owin gets query string parameters

I am trying to get query string parameters from an Owin query. The get operation for the 'test' parameter remains empty, although this parameter was in the query string. How can I read the request parameter from the OWIN host?

Call:

localhost:5000/?test=firsttest 

code:

 public class Startup { public void Configuration(IAppBuilder app) { app.UseHandlerAsync((req, res) => { string paramTest = req.Get<string>("test"); return res.WriteAsync(paramTest); }); } 
+5
source share
1 answer

Get<T> scans the OWIN environment dictionary for any key. However, individual GET request parameters are not part of this dictionary. You can get the full query string using req.QueryString , which is equivalent to req.Get<string>("owin.RequestQueryString") and returns test=firsttest in your case. This can be easily analyzed.

Another option would be something like this:

  app.Use(async (ctx, next) => { var param = ctx.Request.Query.Get("test"); await next(); }); 

IOwinRequest implementation provides you with a syntax query string. Note that the object that receives from IOwinContext.Request implements IOwinRequest , while the object that is passed to UseHandlerAsync has a completely different type ( Owin.Types.OwinRequest ) that does not provide a context or parsing line (afaik).

+5
source

All Articles