Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <a href="https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack.ServiceInterface/AuthenticateAttribute.cs">Authenticate</a> attribute is just a plain ServiceStack <a href="https://github.com/ServiceStack/ServiceStack/wiki/Filter-attributes">Request Filter Attribute</a>, i.e. it works in both MVC and ServiceStack.</p> <p>Applying this filter will return a <strong>401 UnAuthorized</strong> response for all non-HTML requests. e.g. If you called this with Ajax, you could detect this error response and do the redirect on the client.</p> <p>From v3.9.23+ of ServiceStack the <code>[Authenticate]</code> attribute will automatically redirect all Authentication errors to <code>~/login</code> url by default.</p> <p>You can override this url when you register the AuthFeature, e.g:</p> <pre><code>Plugins.Add(new AuthFeature(...) { HtmlRedirect = "/path/to/my/login" }); </code></pre> <p>Which will apply globally to all <code>[Authenticate]</code> attributes or you can override this on an adhoc basis with:</p> <pre><code>[Authenticate(HtmlRedirect="/path/to/my/login")] </code></pre> <p>Note: Attributes are inheritable so you can add this once to a <strong>SecuredService</strong> class and all subclasses will inherit its behaviour.</p> <h2>Redirecting manually</h2> <p>To redirect an UnAuthorized HTML request manually you can do your own checking + redirection with:</p> <pre><code>public object Secured(Request request) { if (!base.SessionAs&lt;MyCustomSession&gt;().IsAuthenticated) return new HttpResult(HttpStatusCode.Redirect, "Un Authorized") { Headers = { {"Location", "/path/to/login" } } }; } </code></pre> <p>There is also a DRY wrapper around the above redirect which you can use instead:</p> <pre><code>public object Secured(Request request) { if (!base.SessionAs&lt;MyCustomSession&gt;().IsAuthenticated) return HttpResult.Redirect("/path/to/login"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload