473,387 Members | 3,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem referencing IPrincipal from my base page class...

I'm trying to create a base page class for my project (am new to
ASP.NET, so am a bit stumped) - I'm using VS.NET 2003, btw.

OK, my dummy base page class is shown below:

using System;
using System.Web;
using System.Web.UI;
using System.Web.Security;
using System.Security.Principal;

namespace NewBarn.WebModules
{
public class ltAdminPage2 : System.Web.UI.Page
{
private IPrincipal p = HttpContext.Current.User;

public ltAdminPage2()
{
}

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}

}
}
In this project, I'm also implementing custom security, and in this
base page class, I want to determine the current user's roles etc. by
accessing the HttpContext.Current.User.

However, this line seems to be tripping things up for some reason:
private IPrincipal p = HttpContext.Current.User;

If I try and create a .aspx page and change the code-behind to inherit
from ltAdminPage2 rather than System.Web.UI.Page, VS.NET won't let me
open that page in design view.

When I try to open the .aspx in VS.NET, I get an error: "The file
could not be loaded into the Web Forms designer. Please correct the
following error and then try loading it again: An exception occurred
while trying to create an instance of NewBarn.WebModules.ltAdminPage2.
The exception was 'Object reference not set to an instance of an
object.'. Make sure all of the classes used in the page are built or
referenced in the project."

If I comment out the IPrincipal line, it opens the file just fine (but
obviously I can't access the current user's Principal).

What have I done wrong? Am I not referencing the IPrincipal properly?

Confused.

Mike Taylor
Nov 18 '05 #1
2 1749
when you page is opened in design mode, HttpContext is null, so the
HttpContext.Current.User reference thows an error. you need to add code to
detect that the page is in design mode (there is no builtin property, so its
common to test HttpContext) and not use any feature that will not work.

-- bruce (sqlwork.com)
"Mike Taylor" <mi**@mjt.org.uk> wrote in message
news:98**************************@posting.google.c om...
I'm trying to create a base page class for my project (am new to
ASP.NET, so am a bit stumped) - I'm using VS.NET 2003, btw.

OK, my dummy base page class is shown below:

using System;
using System.Web;
using System.Web.UI;
using System.Web.Security;
using System.Security.Principal;

namespace NewBarn.WebModules
{
public class ltAdminPage2 : System.Web.UI.Page
{
private IPrincipal p = HttpContext.Current.User;

public ltAdminPage2()
{
}

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}

}
}
In this project, I'm also implementing custom security, and in this
base page class, I want to determine the current user's roles etc. by
accessing the HttpContext.Current.User.

However, this line seems to be tripping things up for some reason:
private IPrincipal p = HttpContext.Current.User;

If I try and create a .aspx page and change the code-behind to inherit
from ltAdminPage2 rather than System.Web.UI.Page, VS.NET won't let me
open that page in design view.

When I try to open the .aspx in VS.NET, I get an error: "The file
could not be loaded into the Web Forms designer. Please correct the
following error and then try loading it again: An exception occurred
while trying to create an instance of NewBarn.WebModules.ltAdminPage2.
The exception was 'Object reference not set to an instance of an
object.'. Make sure all of the classes used in the page are built or
referenced in the project."

If I comment out the IPrincipal line, it opens the file just fine (but
obviously I can't access the current user's Principal).

What have I done wrong? Am I not referencing the IPrincipal properly?

Confused.

Mike Taylor

Nov 18 '05 #2
Thanks Bruce - so simple when you know how... :-)

Mike
"bruce barker" <no***********@safeco.com> wrote in message news:<uE**************@TK2MSFTNGP09.phx.gbl>...
when you page is opened in design mode, HttpContext is null, so the
HttpContext.Current.User reference thows an error. you need to add code to
detect that the page is in design mode (there is no builtin property, so its
common to test HttpContext) and not use any feature that will not work.

-- bruce (sqlwork.com)
"Mike Taylor" <mi**@mjt.org.uk> wrote in message
news:98**************************@posting.google.c om...
I'm trying to create a base page class for my project (am new to
ASP.NET, so am a bit stumped) - I'm using VS.NET 2003, btw.

OK, my dummy base page class is shown below:

using System;
using System.Web;
using System.Web.UI;
using System.Web.Security;
using System.Security.Principal;

namespace NewBarn.WebModules
{
public class ltAdminPage2 : System.Web.UI.Page
{
private IPrincipal p = HttpContext.Current.User;

public ltAdminPage2()
{
}

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}

}
}
In this project, I'm also implementing custom security, and in this
base page class, I want to determine the current user's roles etc. by
accessing the HttpContext.Current.User.

However, this line seems to be tripping things up for some reason:
private IPrincipal p = HttpContext.Current.User;

If I try and create a .aspx page and change the code-behind to inherit
from ltAdminPage2 rather than System.Web.UI.Page, VS.NET won't let me
open that page in design view.

When I try to open the .aspx in VS.NET, I get an error: "The file
could not be loaded into the Web Forms designer. Please correct the
following error and then try loading it again: An exception occurred
while trying to create an instance of NewBarn.WebModules.ltAdminPage2.
The exception was 'Object reference not set to an instance of an
object.'. Make sure all of the classes used in the page are built or
referenced in the project."

If I comment out the IPrincipal line, it opens the file just fine (but
obviously I can't access the current user's Principal).

What have I done wrong? Am I not referencing the IPrincipal properly?

Confused.

Mike Taylor

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris | last post by:
Hi I'm writing a class for my program that implements the iprinciple interface. my code is as follows: public class BranchBuilderPrincipal : System.Security.Principal.IPrincipal { private...
4
by: Edward Diener | last post by:
I have a class Y in assembly B which is derived from a class Z in assembly C. So I correctly add a reference to assembly C in assembly B, build assembly B and everything builds fine. Now I create...
5
by: | last post by:
Hi, I'm trying to use the cookie munging session handling behaviour of asp.net instead of cookies themselves as I'm finding quite a few people are barring cookies (especially AOL users). If I...
5
by: SoftLion | last post by:
Hi, I've created a default asp.net web page and dragged a DataGrid inside it. I would like to create a simple custom class derived from DataGrid to hide all relevant code in it, instead of putting...
1
by: Mike | last post by:
Hello, I am attempting to develop a class that will inherit from System.Web.UI.Page to serve as a the base class for all of the code behind classes in my web application. I would like to store...
5
by: Keith Jakobs, MCP | last post by:
Hi All.... I'm having a HECK of a time connecting to Active Directory using VB in Visual Studio.NET 2003. Can anyone PLEASE help me? All I am trying to do is list the current members of our...
2
by: Alex Maghen | last post by:
I want to create a utility function that will seach the current page for one of my UserControls by it's type. So, let's say that I have a UserControl whose class I defined as follows: namespace...
1
by: matt | last post by:
Hi, I have two very similar pages, whose codebehind I'd like to derive from the same base class so I can reuse the controller logic. For (hopeful) clarity I'll try and draw this in ASCII-UML!...
0
by: sloan | last post by:
I'm working on a custom IPrincipal. Sometimes I use the "good ole" MS system of strings. Lately, I've been storing my roles and rights as Guids. Check out the below code. I'm not sure if...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.