Ticket T975297
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

Bypass the login Page in Blazor XAF - using parameter passed in URL

Blazor - Obtain request information from HttpContext (query string parameter) for auto login from URL

created 4 years ago

Hi DX Team

I want to create auto login from external URL, like a bellow scenario was explain in bellow link
T234465 - How to skip authentication and automatically redirect a user to the New Password dialog by a link from email | DevExpress Support

but I can not call function for request query string parameter with : HttpContext.Current.Request.Params["id"];

How I can call this function in blazor?

Thanks

Answers approved by DevExpress Support

created 4 years ago (modified a year ago)

Hello Syamsuri,

We described how to implement a similar task in the following ticket: Bypass the login Page in Blazor XAF - using parameter passed in URL. Please try this solution and let us know whether the result meets your requirements.

Access HttpContext in ASP.NET Core (to get cookes, user agent, client IP address, query string and other request information)

The following article from Microsoft documentation describes how to access HttpContext in different situations: Access HttpContext in ASP.NET Core. Take special note of the following from this article:

Additionally, again for security reasons, you must not use IHttpContextAccessor within Blazor apps. Blazor apps run outside of the context of the ASP.NET Core pipeline. The HttpContext isn't guaranteed to be available within the IHttpContextAccessor, nor is it guaranteed to be holding the context that started the Blazor app.

For tasks like this one (unrelated to XAF directly), we also recommend that you look for standard solutions in public community resources like ASP.NET Core Blazor documentation or Stack Overflow, because there are greater chances of finding solutions to general programming problems there. As a rule of thumb, we recommend that you first implement this in a standard ASP.NET Web Forms app – XAF integration will be much easier after.

Caution

I can also share our experience that HttpContext can be null under certain circumstances in the ASP.NET Core Blazor Server app life cycle. For more information, see Blazor and shared state. Internally, we also use IHttpContextAccessor, but check HttpContext for null. Examples:

C#
IHttpContextAccessor httpContextAccessor = <...>; string sizeModeValue = httpContextAccessor.HttpContext?.Request.Cookies[CookieName]; string themeName = httpContextAccessor.HttpContext?.Request.Cookies[CookieName]; var binding = httpContextAccessor.HttpContext?.Features.Get<ITlsTokenBindingFeature>()?.GetProvidedTokenBindingId(); var httpContext = httpContextAccessor.HttpContext; if(httpContext != null && httpContext.User.Identity.IsAuthenticated) { IIdentity identity = httpContext.User.Identity; //... }

Deployment recommendations

If you deploy to Azure SignalR Service, be sure to implement ProxyHubConnectionHandler as shown in our Azure Deployment docs.

When you deploy your Blazor apps to IIS, make certain to activate the following features: WebSocket Protocol and Sticky sessions with Application Request Routing (often forgotten by developers).

See Also

Blazor - How to store HttpContext vars in value manager

    Comments (2)

      Hi Anatol

      Your solutions is work for me,

      Many thanks for your support

      Anatol (DevExpress) 4 years ago

        You are welcome!

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.