Search, User Login, Registration
Hi I see these features are missing in 4.0 beta, or maybe I can't find them?
Hello Peppi Alexandrova,
Search providers have not been implemented yet. You can use ASP.NET Login and CreateUserWizard controls to authenticate existing users or create new users.
Sincerely yours,
Ivan Dimitrov
the Telerik team
"You can use ASP.NET Login and CreateUserWizard controls to authenticate existing users or create new users."
Hi Joe,
Here is what you can do. You can crate a simple user control and there declare LoginForm control. Then you can use this widget to authenticate your users.
<%@ Register TagPrefix="log" Namespace="Telerik.Sitefinity.Security.Web.UI" Assembly="Telerik.Sitefinity" %>
<
log:LoginForm
runat
=
"server"
ID
=
"LogForm1"
/>
SecurityManager.SetAuthenticationCookie(SystemManager.CurrentHttpContext, user.ProviderName, user, true)
Hi Joe Keller,
To register a new user you can use CreateUserWizardForm, but the current implementation will not allow you to create a user if you do not have permissions for "Create"
Regards,
Ivan Dimitrov
the Telerik team
When trying to create the control in design mode i get
Error Creating Control - LogForm1
the type initializer for 'Telerik.Sitefinity.Security.SecurityManager' threw an exception.
Hello Kristian,
I saw what the problem was. Inside Page Edit mode there is no this.Page.Form that we use inside CreateUserWizardForm control - OnPreRender method.
You can create the control in the code behind and add it to the controls collection
var cuwf =
new
Telerik.Sitefinity.Security.Web.UI.CreateUserWizardForm();
if
(!cuwf.IsDesignMode() && !cuwf.IsBackend())
Thanks!
Since, I am using the LoginForm control. Now that I am adding it using code how would I do a redirect to another page?
Leaving the control as is the control ends up displaying:
Object moved to here.
Hello Kristian,
Using the control as is posted does not make such redirect for me. Could you drop the control on a page (without ) any other controls and let me know the steps that lead to "object moved"
Object moved generally appears when you change the host or your are making some domain/newtwork routings. We use the same control for backend logging, so getting this error on the public instance would be equivalent to getting the "object moved" when you try to access the backend.
Kind regards,
Ivan Dimitrov
the Telerik team
Here is my code
Login.ascx
<
asp:Panel
ID
=
"Panel1"
runat
=
"server"
>
</
asp:Panel
>
protected
void
Page_Load(
object
sender, EventArgs e)
var lf =
new
Telerik.Sitefinity.Security.Web.UI.LoginForm();
Panel1.Controls.Add(lf);
Just needed to set the DestinationPageUrl !
lf.DestinationPageUrl =
"/page"
;
Ivan,
Hi Andrey,
The control is getting styles from the current theme stylesheet. You can use ResourceLinks to style the control
<sf:ResourceLinks id=
"resourceLinks"
runat=
"server"
>
<sf:ResourceFile Name=
"CSS/test1.css"
/>
</sf:ResourceLinks>
Ivan,
Hello Andrei,
Yes, we promised to implement these controls and now you see them in your toolbox.
1. We will work on selectors and I hope that we will have them for the official release.
2. "Login to manage the site" - this could be changes from Sitefinity >> Administration >> Labels where the key is Key: LoginToManage .
Another option here is using ResourceClassId of the Login control - Sitefinity >> Administration >> Settings >> Advanced >> Toolboxes >> PageControls >> Sections >> Login.
You can create a custom label and set its ResourceClassId from Sitefinity >> Administration >> Labels
3. This is a bug that we logged for fixing. Your Telerik points have been updated.
Regards,
Ivan Dimitrov
the Telerik team
Ivan,
Ivan,
For some reason in build 4.0.992.0 I get kicked out when I use the code:
protected void Page_Load(object sender, EventArgs e)
if (!this.Page.IsBackend() && !this.Page.IsDesignMode())
// get the login button
var b = this.LoginForm.FindControl("LoginButton") as Button;
// subscribe for click event
b.Click += new EventHandler(b_Click);
// get the current user
var user = SecurityManager.GetCurrentUser();
if (user != null)
// get the identity
var ident = user.Identity.Name;
// force log out for this stest
SecurityManager.Logout();
if (!this.LoginForm.IsBackend() && !this.LoginForm.IsDesignMode())
Hello Andrei,
Could you try to use this.IsDesignMode() instead of this.Page.IsDesignMode().
IsDesignMode() is a control extension method from System.Web.UI.ControlExtensions
Greetings,
Ivan Dimitrov
the Telerik team
Ivan,
I was just having a look at:
www.sitefinity.com/.../reply-thread.aspx
where you recommend the same thing. I have already tried it and it did not work. I have some code which writes into a database when someone has accessed a page. So i do not want it to write anything in the database when the page is accessed from the backend.
So I opened the project in Visual Studio 2010 and set ~/Sitefinity/Default.aspx as the Starting page. Put a breakpoint inside the if statement and attempted to access the page with the code from the Backend. The breakpoint gets hit twice for some reason. First time it gets hit, it works. The second time it gets hit it doesn't. All I do is click the page to edit it. Until it loads in design mode, the code is run through twice. First time it does not write anything to the database, the second time it writes to the database.
Any further thoughts?
Many thanks,
Andrei
Or this link, is the same.
http://www.sitefinity.com/devnet/forums/sitefinity-4-x/sdk/how-to-know-that-we-are-in-edit-mode.aspx#0
Hello Andrei,
I am not able to replicate the issue locally when the code runs in Page_Load event of a user control. For controls that inherit from SimpleView you should use InitializeControls. You could try using try using OR condition instead of AND so that both cases - design and backend will be covered.
Best wishes,
Ivan Dimitrov
the Telerik team
Ivan,
The code is:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UserName.ascx.cs" Inherits="SitefinityWebApp.Controls.UserName" %>
<
p
>Welcome <
asp:LoginName
ID
=
"LoginName"
runat
=
"server"
/> [<
asp:LoginStatus
ID
=
"LoginStatus"
runat
=
"server"
onloggingout
=
"LoginStatus_LoggingOut"
/>]</
p
>
using System;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Data.SqlClient;
using System.Data;
using Telerik.Sitefinity.Security;
using Telerik.Sitefinity.Web.UI;
namespace SitefinityWebApp.Controls
public partial class UserName : System.Web.UI.UserControl
protected void Page_Load(object sender, EventArgs e)
if (!this.IsBackend() && !this.IsDesignMode())
if (!string.IsNullOrEmpty(_connectionString))
RecordUser();
protected void LoginStatus_LoggingOut(object sender, LoginCancelEventArgs e)
Server.Transfer("~/Default");
private void RecordUser()
SqlConnection connection = new SqlConnection(ConnectionString);
connection.Open();
try
SqlCommand command = new SqlCommand("INSERT INTO Report (UserName, TimeRead) VALUES (@username, @timeread);", connection);
command.CommandType = System.Data.CommandType.Text;
command.Parameters.Add(new SqlParameter("@username", SqlDbType.NVarChar, 50)).Value = SecurityManager.GetCurrentUser().Identity.Name;
command.Parameters.Add(new SqlParameter("@timeread", SqlDbType.DateTime2)).Value = DateTime.Now;
command.ExecuteNonQuery();
finally if (!(connection.State == ConnectionState.Closed)) connection.Close();
private string _connectionString = "";
public string ConnectionString
get return _connectionString;
set _connectionString = value;
Hello Andrei,
I am not able to replicate the issue with this.IsBackend() and this.IsDesignMode(). We use these extensions in our code as well and so far they apply without issues. Can you replicate the problem with a new project with the latest build?
Greetings,
Ivan Dimitrov
the Telerik team
Ivan,
Yes I replicated the issue in a new project. I wish I had a way of creating videos like you do. What do you use? I don't have the full Adobe Acrobat on my machine but I see a few Open Source applications. Until I figure the video bit out, see my code below.
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CustomLogin.ascx.cs" Inherits="SitefinityWebApp.Controls.CustomLogin" %>
<
div
align
=
"center"
>
<
asp:Login
ID
=
"LoginForm"
runat
=
"server"
BackColor
=
"#F7F6F3"
BorderColor
=
"#E6E2D8"
BorderStyle
=
"Solid"
BorderWidth
=
"1px"
DisplayRememberMe
=
"False"
Font-Names
=
"Verdana"
Height
=
"150px"
Width
=
"350px"
BorderPadding
=
"4"
ForeColor
=
"#333333"
>
<
LabelStyle
Font-Size
=
"1.4em"
/>
<
InstructionTextStyle
Font-Italic
=
"True"
ForeColor
=
"Black"
Font-Size
=
"3em"
/>
<
LoginButtonStyle
BackColor
=
"#FFFBFF"
BorderColor
=
"#CCCCCC"
BorderStyle
=
"Solid"
BorderWidth
=
"1px"
Font-Names
=
"Verdana"
Font-Size
=
"1.5em"
ForeColor
=
"#284775"
/>
<
TextBoxStyle
Font-Size
=
"1.5em"
Width
=
"200px"
/>
<
TitleTextStyle
BackColor
=
"black"
Font-Bold
=
"True"
ForeColor
=
"#FFFFFF"
Font-Size
=
"2em"
/>
</
asp:Login
>
</
div
>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Sitefinity.Security;
using Telerik.Sitefinity.Services;
using System.Data.SqlClient;
using System.Data;
namespace SitefinityWebApp.Controls
public partial class CustomLogin : System.Web.UI.UserControl
protected void Page_Load(object sender, EventArgs e)
if (!this.IsBackend() && !this.IsDesignMode())
// get the login button
var b = this.LoginForm.FindControl("LoginButton") as Button;
// subscribe for click event
b.Click += new EventHandler(b_Click);
// get the current user
var user = SecurityManager.GetCurrentUser();
if (user != null)
// get the identity
var ident = user.Identity.Name;
// force log out for this test
SecurityManager.Logout();
void b_Click(object sender, EventArgs e)
// Login the user.
var now = DateTime.UtcNow;
var ip = SystemManager.CurrentHttpContext.Request.UserHostAddress;
var manager = UserManager.GetManager();
var user = manager.GetUser(LoginForm.UserName);
user.IsLoggedIn = true;
user.LastLoginIp = ip;
user.LastLoginDate = now;
user.LastActivityDate = now;
SecurityManager.SetAuthenticationCookie(SystemManager.CurrentHttpContext.Response, "Default", user, true);
manager.Provider.SuppressSecurityChecks = true;
manager.SaveChanges();
manager.Provider.SuppressSecurityChecks = false;
if (!string.IsNullOrEmpty(_connectionString))
RecordUser(LoginForm.UserName);
Response.Redirect(_destinationPageUrl);
private void RecordUser(string username)
SqlConnection connection = new SqlConnection(ConnectionString);
connection.Open();
try
SqlCommand command = new SqlCommand("INSERT INTO Report (UserName, TimeRead) VALUES (@username, @timeread);", connection);
command.CommandType = System.Data.CommandType.Text;
command.Parameters.Add(new SqlParameter("@username", SqlDbType.NVarChar, 50)).Value = username;
command.Parameters.Add(new SqlParameter("@timeread", SqlDbType.DateTime2)).Value = DateTime.Now;
command.ExecuteNonQuery();
finally if (!(connection.State == ConnectionState.Closed)) connection.Close();
private string _connectionString = "";
public string ConnectionString
get return _connectionString;
set _connectionString = value;
private string _destinationPageUrl = "~/Default.aspx";
public string DestinationPageUrl
get return _destinationPageUrl;
set _destinationPageUrl = value;
Ivan,
I got hold of an application and did a video for you but I can't attach it because .zip files are not allowed. Also, its bigger than 2MB. Its actually 13MB.
Can I email it to you?
Many thanks,
Andrei
Hello Andrei,
Again, there is no issue at my end with your code. You can host your video somewhere and I will check it.
All the best,
Ivan Dimitrov
the Telerik team
Ivan,
Here is the link: https://www.transferbigfiles.com/47030b13-6e6b-4020-a48d-86d03d2a9ce4?rid=nw5c%2fw2kiydsyhFpcrhSUg%3d%3d
Hopefully, it will prove that I am not going crazy, because I am really lost for words. Your video demonstrates that it is working.
Let me know.
Many thanks again,
Andrei
Hello Andrei,
We had similar bug that appears only in IE. There should not be an issue if you use FireFox. We fixed the issue and the fix will appear in the weekly build that we will have next week.
Greetings,
Ivan Dimitrov
the Telerik team
Ivan,
That answers it. I am not very big on IE either, but because our customers use it, I must develop against it.
Thank you very much again.
Andrei
Ivan,
I have downloaded the latest version of the RC (1030) and when compiling my Login Control I get the following
Telerik.Sitefinity.Security.SecurityManager' does not contain a definition for 'SetAuthenticationCookie
I checked the class and indeed SetAuthenticationCookie does not exist. What happened and what do I use now?
Many thanks,
Andrei
Hi,
We made the method internal. You can use our Login control implemented with the RC release, try using AuthenticateUser or follow this post to authenticate the user by using web request.
Greetings,
Ivan Dimitrov
the Telerik team
Ivan,
Firstly, just to say that the link in the email 'Click here to post a reply.....' did not work. Not sure why.
Secondly thanks for the explanation, I will give it a go and let you know.
Thirdly, how safe is it to develop against the RC? Is it worth waiting?
Many thanks again,
Andrei
Hi,
Our web team will check what the problem is with "Click here to post a reply.....". We make make changes to the code everyday, because we are fixing bugs and we are re factoring entire code base for the official release. Currently you can use AuthenticateUser method which can be accessed.
Regards,
Ivan Dimitrov
the Telerik team
Ivan,
In the latest version I can not find the 'LoginToManage' label in the Labels module. How do I change the 'Login to manage this site message in the latest version?
Many thanks,
Andrei
Ivan,
Sorry, I found the Label. I was typing "logintomanage" rather than "LoginToManage". I did not know that I should get the upper and lower case as well. Although..., why??? Your RegEx should do that.
Anyway, sorry again.
Andrei