467,211 Members | 1,202 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,211 developers. It's quick & easy.

Forms auth for directory

Hi guys

Ok, I have a website which has an "Artists Only" section, for which you have
to login for. This section is contained within its own directory on the
server "/aonly".

I want to make people login before they can access this directory, with a
User control on each page for logging in. I'd like to use Forms auth and sql
server (i know how to check that against the entered details).

I also want a login.aspx page so that if their session expires, it's easy to
log back in.

Question is.. how do I create the forms auth and make it protect the
"/aonly" directory, and can I make the user control authenticate the user,
and then forward to the protected directory?

HOpe that makes sense!

Cheers
Dan
Nov 19 '05 #1
  • viewed: 1125
Share:
4 Replies
You should enable forms authentication in your root web.config (root of you
application, that is). For the subdirectory, you should then set the authorization
to not allow anonymous users. I presume the rest of the site is accessible
to anonymous users?

Here are the docs for configuring forms authentication:

http://msdn.microsoft.com/library/de...gngrfforms.asp

And here's how you'd set the authorization:

http://msdn.microsoft.com/library/de...asp?frame=true

Now since you're looking to control authorization on a subdirectory, the
authorization could go into an independant web.config in the child directory
you want to contol access to.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi guys

Ok, I have a website which has an "Artists Only" section, for which
you have to login for. This section is contained within its own
directory on the server "/aonly".

I want to make people login before they can access this directory,
with a User control on each page for logging in. I'd like to use Forms
auth and sql server (i know how to check that against the entered
details).

I also want a login.aspx page so that if their session expires, it's
easy to log back in.

Question is.. how do I create the forms auth and make it protect the
"/aonly" directory, and can I make the user control authenticate the
user, and then forward to the protected directory?

HOpe that makes sense!

Cheers

Dan


Nov 19 '05 #2
Thanks Brock,

That seems to have got all the security stuff setup. I'm assuming I put the
code to authenticate against SQL in a function called by the clicking of my
signup button, is that right?

In which case, when I've authenticated a user, what do I need to set in
order for Forms authentication to let them in?

Cheers
Dan
"Brock Allen" wrote:
You should enable forms authentication in your root web.config (root of you
application, that is). For the subdirectory, you should then set the authorization
to not allow anonymous users. I presume the rest of the site is accessible
to anonymous users?

Here are the docs for configuring forms authentication:

http://msdn.microsoft.com/library/de...gngrfforms.asp

And here's how you'd set the authorization:

http://msdn.microsoft.com/library/de...asp?frame=true

Now since you're looking to control authorization on a subdirectory, the
authorization could go into an independant web.config in the child directory
you want to contol access to.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi guys

Ok, I have a website which has an "Artists Only" section, for which
you have to login for. This section is contained within its own
directory on the server "/aonly".

I want to make people login before they can access this directory,
with a User control on each page for logging in. I'd like to use Forms
auth and sql server (i know how to check that against the entered
details).

I also want a login.aspx page so that if their session expires, it's
easy to log back in.

Question is.. how do I create the forms auth and make it protect the
"/aonly" directory, and can I make the user control authenticate the
user, and then forward to the protected directory?

HOpe that makes sense!

Cheers

Dan


Nov 19 '05 #3
k
You want to do something like this

public void Login_Click(Object sender, EventArgs E)
{

_UserName = UserName.Value;
_Password = UserPass.Value;

if (CheckUserAndPassword (_ServerName, _DatabaseName,_UserName
,_Password))
{
System.Web.Security.FormsAuthentication.RedirectFr omLoginPage(UserName.Value,false);
}
else
{
Msg.Text = "Invalid Credentials: Please try again";
}
}
which puts them back to the originally requested URL.

Kirsty

Nov 19 '05 #4
> That seems to have got all the security stuff setup. I'm assuming I
put the code to authenticate against SQL in a function called by the
clicking of my signup button, is that right?
Right - you'll have to write the code to do the actual authentication against
your database of usernames/passwords.
In which case, when I've authenticated a user, what do I need to set
in order for Forms authentication to let them in?


So once you know the user has provided valid credntials, you use FormsAuthentication.RedirectFromLoginPage("TheirUs ername",
false) or FormsAuthentication.SetAuthCookie to tell ASP.NET that they're
logged in.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Justin | last post: by
3 posts views Thread by Smokey Grindle | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.