How to read IHttpRequest to gain access to session in validation, on self-hosted ServiceStack? -


There are several posts on this. I am doing 3.9.71 on the way.

First of all, @ Scott has been answered by. In general, you can not actually use the session using something similar to the service. SASAS <> Just because the service is executed before verification.

Second, the answer is @PISCHPA. Here, there is a way to catch the session, even in the verification phase, technically we have

  • cash client , which can be injected Validator
  • The built-in request, which will be retrieved internally within SessionFeature.GetSessionKey () . Checking the method for the service stack's own IHttpRequest , if failing, will fall back to this on HttpContext.Current.Request . Of course, because we have goes to SessionFeature.GetSessionKey () whatever method of passing HttpContext.Current.Request , which is actually ASP.NET specific .

Once you configure the service stack to self-host mode, it fails because we have HttpContext.Current.Request is not . The following is the code that fails (starts with GetSessionId GetSessionKey ).

  public static string GetSessionId (IHttpRequest httpReq = null) {if (httpReq == null & amp; & amp; HttpContext.Current throw == NULL) {New NotImplementedException ( "only ASP.NET The requests are accessible accessible through Singletons "); } HttpReq = (httpReq ?? HttpContext.Current.Request.ToRequest (faucet)); Return httpReq.GetSessionId (); }  

It seems that this is so close to the case so far. Either way we are in the IHttpRequest verifier?

Update

Given can get hold of ValidationFilters.RequestFilter are ServiceStackV3 action, it seems that the intention is to Already have note that if the verifier tool IRequiresHttpRequest , it injects the request in the verifier.

  public static class ValidationFilters {public static void RequestFilter (IHttpRequest request, IHttpResponse race, object RequestDto) {var recognizer = Verifier Cache.GetValidator (request, requestDto.GetType ()); If (validator == blank) return; Var validatorWithHttpRequest = IRequiresHttpRequest as the verifier; If (validatorWithHttpRequest! = Faucet) with HttpRequest.HttpRequest = req; Var ruleSet = req.HttpMethod; Var Validation Available = Validate. Validated (New Validation Resource (Request Deto, Blank, New MultilSetset Calculator (Ruleset)); I tried to apply the  IRequiresHttpRequest  interface to my verifier, but unfortunately it is still empty. Obviously this is due to a bug on my code, so this is not a problem. 

above, according to the update, move your verifier tool IRequiresHttpRequest make To do, and are ready for you

  Public MyDtoValidator: AbstractValidator & LT; MyDto>, IRequiresHttpRequest  

The validity filter will then inject a request on your behalf because it will set the verifier to fire. You can then get the request via property HttpRequest . I tested it on a simple solution, and it worked.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -