How to check if a user is registered (authenticated) in the sitefinity widget template?

I need to display a piece of text through a widget template for users who are not logged in. The widget template serves the dynamic Sitefinity module, the module is partially accessible for users without registration. I want non-registered users to receive a message that they must be logged in to read the full content.

I set permissions for the fields, and everything works as it should, but the only missing item displays a message for users without registration.

I tested this in a simple web form test file, and it works:

<p>You are <asp:Literal ID="UserStatus" runat="server" />.</p>

and the code is behind:

public string Name { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.Request.IsAuthenticated)
        {
            UserStatus.Text = "Logged in";
        }
        else
        {
            UserStatus.Text = "Not logged in";
        }
    }

, Code-behind Sitefinity, , :

Object reference not set to an instance of an object.

:

UserStatus.Text = "Logged in";

Code-behind widget ?

+4
2

Sitefinity , , ascx, , , , .

, Sitefinity api, , , , :

protected void Page_Load(object sender, EventArgs e)
{

    if  (ClaimsManager.GetCurrentIdentity().IsAuthenticated)
        UserStatus.Text = "Logged in";
    else
        UserStatus.Text = "Not logged in";
}

:

using Telerik.Sitefinity.Security.Claims;

, , Import Register:

<%@ Register TagName="LoginStatus" TagPrefix="Custom" Src="~/Controls/LoginStatus/LoginStatus.ascx" %>

:

<Custom:LoginStatus runat="server" />

: SiteFinity,

+2

autoeventwireup = "true"?

, :

"/" >

- . , , . , shoul auth, .

.

0

All Articles