p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

aspdotnet_website_programming thread: logging into new admin page


Message #1 by <robert@C...> on Mon, 20 May 2002 11:36:07 -0700
Hello,
    I created a new admin page that holds all the admin links for the
various modules.  However when I log in as the admin, I get a "Specified
cast is not valid" error (full error text below).
I have the admin page prompt for authorization before letting anyone
onto that page.
Here's the Page_Load code in Admin.aspx.cs:
// check if the current user is allowed to administer the site
if (!Context.User.Identity.IsAuthenticated || 
	
!((SitePrincipal)Context.User).HasPermission((int)SiteManagerPermissions
.AdministerSite))
	{
		// if not, redirect to the Login page
	
Response.Redirect("/ThePhile/Modules/Users/Login.aspx?ShowError=true",
true);
	}
I created a section in the Enum.cs page for a new namespace called
"Wrox.WebModules.SiteManager":
namespace Wrox.WebModules.SiteManager
{
   public enum SiteManagerPermissions
   {
      AdministerSite = 600
   };
}

In SQLServer, I added rows for the new SiteManager permissions.
CategoryID	Description
1	Accounts
2	NewsManager
3	Polls
4	MailingLists
5	Forums
6	SiteManager
PermissionID	Description	CategoryID
100	CreateNewUser	1
101	DeleteUser	1
102	CreateRoles	1
103	UpdateRoles	1
200	AdministerNews	2
201	PublishNews	2
202	SubmitNews	2
300	AdministerPolls	3
400	AdministerMailingLists	4
401	SendNewsletter	4
500	AdministerForumsCategories	5
501	ModerateForums	5
502	EditForumsSettings	5
600	AdministerSite	6
601	AdministerSpecificPage	6
RoleID	PermissionID
2	100
2	102
2	101
2	103
2	202
2	200
2	201
2	400
2	401
2	300
2	500
2	501
2	502
2	600
	
This is the full error: 
An unexpected error has occurred on this page. The system administrators
have been notified. Please feel free to contact us with the information
surrounding this error.
The error occurred in: http://localhost/thephile/admin.aspx
Error Message: Specified cast is not valid. 

Stack Trace:
System.InvalidCastException: Specified cast is not valid. at
Wrox.WebModules.SiteManager.AdminPage.Page_Load(Object sender, EventArgs
e) in c:\inetpub\wwwroot\thephile\admin.aspx.cs:line 27 at
System.EventHandler.Invoke(Object sender, EventArgs e) at
System.Web.UI.Control.OnLoad(EventArgs e) at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Page.ProcessRequestMain()


  Return to Index