Sunday 16 May 2010

Login Controls

Select "Website" on toolbar, "ASP.NET Configuration", "Security" tab, "Select Authentication Type", select from "Internet (website log in)" or "Local Network (intranet)". I selected Internet.

"Security" tab, "Create User", add details, such as username & password, apply a role.
Close "ASP.NET Configuration" screen.

Right Click project folder, "Add New Item", "Web Form". Name it "Login", Drag-Drop a Login control from "Toolbox" onto page.
"Auto Format" to change colour, or make "Template" to change specific text
"Properties" of Login box, "DestinationPageURL", select "Despatch Page". This will determine whether the user is an "Admin" user or "Staff" user. If the user is "Admin" he will be transferred to the "Default" page. However, if it is a "Staff" user the "Staff" Page will appear.

Enter the code below into the page load event of Despatch page to do this click on the plus sign next to the Despatch page and select the Despatch.aspx.cs page which will be below it:


{
if (User.Identity.IsAuthenticated == false)
{
Server.Transfer("login.aspx");
}
if (Roles.IsUserInRole("Staff") == true)
Server.Transfer("StaffPage.aspx");// Load this page

Server.Transfer("Default.aspx");// Otherwise load this page
}
}

Run application by clicking on "Play".

No comments:

Post a Comment