Base page error at design time

M

Mark

I have .aspx code-behinds that inherit from the class below. The code runs
just fine, but the form designer bombs at design time when trying to view
the .aspx page in VS.NET 2003. If I comment out the single line of code
below, then there is no error. I posted the error message below - it
implies that this code is being run at design time, but it bombs due to the
fact that it isn't run time. Is there a line of code I could add to only
allow the code below to execute at run-time instead of design time?

Thanks,
Mark

public class MyBase: System.Web.UI.Page
{
public MyBase()
{
//This is the line that bombs. If it's commented out, the design time
viewer works fine.
System.Security.Principal.IIdentity ii = User.Identity;
//The some other code that does something with this identity.
}
}

**** THE 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 foo.bar. 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.
 
M

Mark

The code below appears to have solved my problem:

if (HttpContext.Current != null)
{
//This code bombs if it's not in the IF statement during design time - not
run time.
//I believe this is because pages inherit from it, and therefore it has to
create
//an instance of the object at design time. Since there is no "user" at
runtime,
//it bombs.
System.Security.Principal.IIdentity ii = User.Identity;
_strUser = ii.Name;
}

Mark
 

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

Top