Context and global.asax

  • Thread starter Thread starter Arjen
  • Start date Start date
A

Arjen

Hi,

I load my website settings inside the global.asax file. For this I have to
use the context, to get the roles from the current browsing client.

The problem is that there is no context at that time. (no reference) When I
add these code
lines (from global.asax) inside an aspx file, then it works. Because there
is a context.

How can I use this code inside the global.asax file?

I tried it in this:
protected void Application_BeginRequest(Object sender, EventArgs e) {}
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{}

But this did not work. I'm using asp.net 2.0.

Hope someone can help.
 
Hi,


I'm not very clear of what you mean with contex and roles, are you trying to
access Win auth? If so do this:

protected void Session_Start(Object sender, EventArgs e)
{
string login = WindowsIdentity.GetCurrent().Name.Substring(
WindowsIdentity.GetCurrent().Name.LastIndexOf(@"\")+1 );
Session["SystemUser"] = login ;
}


cheers,
 
What do you mean by 'roles'.
Can you be more specific about what you want to do in global.asax?
 
I use form authentication.

When a user request a page it must first load some settings. These settings
will be placed inside the context.items. I can add this method in all pages
but that is not what I want. Easier will be one declaration...

This loading happens inside the global.asax file. This way it load
automaticly the settings, no matter what page the user request. This is what
I want.

Now the loading method uses some information from the current browsing
client. It want to know the roles from the current browsing client. I can't
get these from inside the global.asax file. This is the problem. I get the
messege that the object is not set to a reference.

When adding/calling this method from an aspx file then it works... I want
that it works inside the global.asax file.

This is the problem, hope someone haves a solution.

Thanks!


Ignacio Machin ( .NET/ C# MVP ) said:
Hi,


I'm not very clear of what you mean with contex and roles, are you trying
to access Win auth? If so do this:

protected void Session_Start(Object sender, EventArgs e)
{
string login = WindowsIdentity.GetCurrent().Name.Substring(
WindowsIdentity.GetCurrent().Name.LastIndexOf(@"\")+1 );
Session["SystemUser"] = login ;
}


cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Arjen said:
Hi,

I load my website settings inside the global.asax file. For this I have
to
use the context, to get the roles from the current browsing client.

The problem is that there is no context at that time. (no reference) When
I add these code
lines (from global.asax) inside an aspx file, then it works. Because
there is a context.

How can I use this code inside the global.asax file?

I tried it in this:
protected void Application_BeginRequest(Object sender, EventArgs e) {}
protected void Application_AuthenticateRequest(Object sender, EventArgs
e) {}

But this did not work. I'm using asp.net 2.0.

Hope someone can help.
 
Hi,

Okay, after reading my post back... it is not realy reading all the roles it
is checking the roles.

I use this:
HttpContext.Current.User.IsInRole(role);

See also my post on 15:19.

Thanks.
 

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

Back
Top