|
-
Mar 1st, 2004, 11:17 AM
#1
Thread Starter
Frenzied Member
Help with classes (C#) *RESOLVED*
I've written an asp.net page as below:
Code:
<%@ Page Language="C#" %>
<script runat="server">
public class SitePermissions {
private bool viewFiles = false;
private bool addFiles = false;
private bool editFiles = false;
private bool deleteFiles = false;
private bool addClients = false;
private bool editClients = false;
private bool deleteClients = false;
private bool accessAllowed = false;
private bool RoleAccessAllowed( string[] enteredFilePaths,
string checkPermissionType )
{
this.accessAllowed = false;
foreach (string enteredFilePath in enteredFilePaths) {
if ( User.IsInRole( checkPermissionType + ":" + enteredFilePath ) ) {
this.accessAllowed = true;
}
}
return this.accessAllowed;
}
public SitePermissions( string[] roles )
{
this.RoleAccessAllowed( roles, "view_files" );
this.RoleAccessAllowed( roles, "add_files" );
this.RoleAccessAllowed( roles, "edit_files" );
this.RoleAccessAllowed( roles, "delete_files" );
this.RoleAccessAllowed( roles, "add_clients" );
this.RoleAccessAllowed( roles, "edit_clients" );
this.RoleAccessAllowed( roles, "delete_clients" );
}
public bool ViewFiles
{
get
{
return this.viewFiles;
}
}
public bool AddFiles
{
get
{
return this.addFiles;
}
}
public bool EditFiles
{
get
{
return this.editFiles;
}
}
public bool DeleteFiles
{
get
{
return this.deleteFiles;
}
}
public bool AddClients
{
get
{
return this.addClients;
}
}
public bool EditClients
{
get
{
return this.editClients;
}
}
public bool DeleteClients
{
get
{
return this.deleteClients;
}
}
~SitePermissions() {}
}
string strClientPath, strCssPath;
ArrayList roleList = new ArrayList();
string[] roleListArray, splitPath;
SitePermissions UsersRoles;
public void Page_Load( Object sender,
EventArgs e )
{
strClientPath = Request.Params[ "path" ];
if (Request.Browser.Type.ToLower().IndexOf("ie") != -1) {
strCssPath = "general_ie.css";
} else {
strCssPath = "general_moz.css";
}
splitPath = strClientPath.Split(new char[] {'/'});
string tempPath = "";
foreach (string subpath in splitPath) {
if (subpath != "") {
tempPath += "/" + subpath;
roleList.Add( tempPath );
}
}
roleListArray = (string[]) roleList.ToArray( typeof( string ) );
UsersRoles = new SitePermissions( roleListArray );
Progress.Text = UsersRoles.ViewFiles.ToString();
}
</script>
<!-- <%= strClientPath %>.aspx remapped to <%= Request.Path %>?path=<%= strClientPath %> -->
<html>
<head>
<title>HRO'C Client Extranet</title>
<link href="/css/<%= strCssPath %>" type="text/css" rel="stylesheet" />
</head>
<body>
<form runat="server">
<div id="extranetTitle" class="extranetTitle">
Client<br />
Extranet
</div>
<br />
<%= strClientPath %>
<asp:Textbox id="Progress" runat="Server" Textmode="Multiline" Style="position: absolute; top: 250px; left: 400px; width:250px; height: 100px;">Start</asp:Textbox>
</form>
</body>
</html>
Basically there is an error thrown at:
Line 20: if ( User.IsInRole( checkPermissionType + enteredFilePath ) ) {
The error is CS0118: 'System.Web.UI.Page.User' denotes a 'property' where a 'class' was expected
I presuming I cannot access User.IsInRole from within my new class.
This is my first stab at asp.net using OOP so point out where I'm going wrong and where I could improve.
Cheers
DJ
Last edited by dj4uk; Mar 2nd, 2004 at 10:01 AM.
-
Mar 2nd, 2004, 07:16 AM
#2
Thread Starter
Frenzied Member
No one?
I can give more details if needed.
DJ
-
Mar 2nd, 2004, 08:00 AM
#3
Frenzied Member
Exactly what is user.isinrole?
is user a class and isinrole a static method??
More info please 
kind regards
Henrik
-
Mar 2nd, 2004, 09:16 AM
#4
Thread Starter
Frenzied Member
I'm using role based authentication and User.IsInRole returns a true or false value according to whether the role passed in a string matches the roles the user has.
User is an IPrinciple part of the Page object.
DJ
-
Mar 2nd, 2004, 10:00 AM
#5
Thread Starter
Frenzied Member
OK I was stupid the following works:
Code:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Security.Principal" %>
<script runat="server">
public class SitePermissions {
private bool viewFiles = false;
private bool addFiles = false;
private bool editFiles = false;
private bool deleteFiles = false;
private bool addClients = false;
private bool editClients = false;
private bool deleteClients = false;
private bool accessAllowed = false;
private IPrincipal User;
private bool RoleAccessAllowed( string[] enteredFilePaths,
string checkPermissionType )
{
this.accessAllowed = false;
foreach (string enteredFilePath in enteredFilePaths) {
if ( User.IsInRole( checkPermissionType + ":" + enteredFilePath ) ) {
this.accessAllowed = true;
}
}
return this.accessAllowed;
}
public SitePermissions( string[] roles, IPrincipal User )
{
this.User = User;
this.viewFiles = this.RoleAccessAllowed( roles, "view_files" );
this.addFiles = this.RoleAccessAllowed( roles, "add_files" );
this.editFiles = this.RoleAccessAllowed( roles, "edit_files" );
this.deleteFiles = this.RoleAccessAllowed( roles, "delete_files" );
this.addClients = this.RoleAccessAllowed( roles, "add_clients" );
this.editClients = this.RoleAccessAllowed( roles, "edit_clients" );
this.deleteClients = this.RoleAccessAllowed( roles, "delete_clients" );
}
public bool ViewFiles
{
get
{
return this.viewFiles;
}
}
public bool AddFiles
{
get
{
return this.addFiles;
}
}
public bool EditFiles
{
get
{
return this.editFiles;
}
}
public bool DeleteFiles
{
get
{
return this.deleteFiles;
}
}
public bool AddClients
{
get
{
return this.addClients;
}
}
public bool EditClients
{
get
{
return this.editClients;
}
}
public bool DeleteClients
{
get
{
return this.deleteClients;
}
}
~SitePermissions() {}
}
string strClientPath, strCssPath;
ArrayList roleList = new ArrayList();
string[] roleListArray, splitPath;
SitePermissions UsersRoles;
public void Page_Load( Object sender,
EventArgs e )
{
strClientPath = Request.Params[ "path" ];
if (Request.Browser.Type.ToLower().IndexOf("ie") != -1) {
strCssPath = "general_ie.css";
} else {
strCssPath = "general_moz.css";
}
splitPath = strClientPath.Split(new char[] {'/'});
string tempPath = "";
foreach (string subpath in splitPath) {
if (subpath != "") {
tempPath += "/" + subpath;
roleList.Add( tempPath );
}
}
roleListArray = (string[]) roleList.ToArray( typeof( string ) );
UsersRoles = new SitePermissions( roleListArray, User );
Progress.Text += "\n" + UsersRoles.ViewFiles.ToString();
Progress.Text += "\n" + UsersRoles.AddFiles.ToString();
Progress.Text += "\n" + UsersRoles.EditFiles.ToString();
Progress.Text += "\n" + UsersRoles.DeleteFiles.ToString();
Progress.Text += "\n" + UsersRoles.AddClients.ToString();
Progress.Text += "\n" + UsersRoles.EditClients.ToString();
Progress.Text += "\n" + UsersRoles.DeleteClients.ToString();
}
</script>
<!-- <%= strClientPath %>.aspx remapped to <%= Request.Path %>?path=<%= strClientPath %> -->
<html>
<head>
<title>HRO'C Client Extranet</title>
<link href="/css/<%= strCssPath %>" type="text/css" rel="stylesheet" />
</head>
<body>
<form runat="server">
<div id="extranetTitle" class="extranetTitle">
Client<br />
Extranet
</div>
<br />
<%= strClientPath %>
<asp:Textbox id="Progress" runat="Server" Textmode="Multiline" Style="position: absolute; top: 250px; left: 400px; width:250px; height: 100px;">Start</asp:Textbox>
</form>
</body>
</html>
DJ
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|