loginUrl In Web.config?

A

Arpan

I have created a simple ASP.NET calculator in a ASPX page (which exists
in C:\Inetpub\wwwroot\ASPX folder). Before allowing a user to access
this calculator, I want to first find out whether the user is valid or
not. For the sake of brevity, assume that only the user whose UserID is
"simon" (without the quotes) & whose password is "nomis" (again,
without the quotes) will be allowed to access the calculator. So if a
user directly types the URL

http://myserver/ASPX/Calculator.aspx

in the IE address bar, the app will first check whether an
authentication cookie exists or not. I want to do this checking using
the web.config file which looks like this (note that web.config also
exists in the C:\Inetpub\wwwroot\ASPX folder):

<configuration>
<system.web>
<authentication mode="Forms">
<forms name="AuthenticateUser"
loginUrl="ValidateUser.aspx">
<credentials passwordFormat="Clear">
<user name="simon" password="nomis"/>
</credentials>
</forms>
</authentication>
</system.web>
</configuration>

This is the code in Calculator.aspx (which uses a user control & a
code-behind form; neither of them have been reproduced here):

<%@ Register TagPrefix="CBUC" TagName="Calculator"
Src="Calculator.ascx" %>
<script runat="server">
Sub Page_Load(obj As Object, ea As EventArgs)
If Not (IsNothing(Request.Cookies("AuthenticateUser"))) Then
calci.Visible = True
Else
calci.Visible = False
End If
End Sub
</script>
<form runat="server">
<CBUC:Calculator ID="calci" runat="server"/>
</form>

When a user comes to Calculator.aspx for the very first time (by typing
the URL in the address bar), it's pretty obvious that the cookie named
"AuthenticateUser" doesn't exist. So under such circumstances,
shouldn't the user be directed to the "ValidateUser.aspx" page which is
set as the "loginUrl" attribute in the "forms" tag under the
"authentication" element in the web.config file?

Thanks,

Arpan
 
R

Roland Dick

Hi Arpan,

I think you have to add a <deny users="?" /> to the <authorization> tree
of your web.config to make sure unauthorized users are not allowed to
see other pages than your login page. You shouldn't have to worry about
the rest, ASP.NET takes care of directing users to the login page and
back to the calculator after successful authentication.

Hope this helps,

Regards,

Roland
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top