Problem with custom Forms authentication for private sectionof site
I'm new to sitefinity, and I've got a test system set up to run the public/marketing sections of the site.
However I want to setup a private "Members" section that is under custom forms authentication. The Members section, and users are not part of sitefinity.
I've got the user database, and login set up. However when I call
FormsAuthentication.SetAuthCookie(username, false);
It doesn't seem like this is working, the username is not available via HttpContext.Current.User.Identity.Name, and HttpContext.Current.User.Identity.IsAuthenticated is always false. I'm copying this authentication code over from another project, so I know it works.
I'm sure this is something simple I'm overlooking, but I didn't know if Sitefinity overruled any other custom Forms authentication from the web.config file.
Here is what I have in my web.config
<
location
path
=
"Members"
>
<
system.web
>
<
authorization
>
<!-- <allow users="*"/>-->
<
deny
users
=
"?"
/>
</
authorization
>
</
system.web
>
</
location
>
<
system.web
>....
<
authentication
mode
=
"Forms"
>
<
forms
name
=
"Members"
loginUrl
=
"login.aspx"
protection
=
"All"
path
=
"/"
slidingExpiration
=
"true"
/>
</
authentication
>
<
authorization
>
<
allow
users
=
"*"
/>
</
authorization
>
Hello Ed,
Please take a look at this post which explains how Sitefinity authentication works
If the user is not authenticated, then you don't have a current principal and the username will be always null.
Is standard ASP.NET scenario this could be done with the code below
protected
void
Load(
object
sender, EventArgs e)
if
(!IsPostBack)
this
.Login1.LoggedIn +=
new
EventHandler(Login1_LoggedIn);
this
.Login1.Authenticate +=
new
AuthenticateEventHandler(Login1_Authenticate);
void
Login1_Authenticate(
object
sender, AuthenticateEventArgs e)
e.Authenticated = Membership.ValidateUser(
this
.Login1.UserName,
this
.Login1.Password);
void
Login1_LoggedIn(
object
sender, EventArgs e)
HttpCookie cookie =
this
.Response.Cookies[FormsAuthentication.FormsCookieName];
FormsAuthentication.SetAuthCookie(
"username"
,
false
);