By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,319 Members | 2,361 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,319 IT Pros & Developers. It's quick & easy.

Application_AuthenticateRequest cannot read Session variable

P: n/a
I will be using a companyname, user name, and password to authenicate users
in my system. I am trying to save the company name in the session for later
use. I cannot access the Session["CompanyName"] object in the
Application_AuthenticateRequest function. I need the companyname to lookup
the users group to build the GenericPrincipal for the user. My code is below.

Login Page:
int c = SiteSecurity.DBAuthenticate(txtCompanyName.Text, txtUsername.Text,
txtPassword.Text);
if (c > 0) {
//save the company name into the session
Session.Add("CompanyName", txtCompanyName.Text);
FormsAuthentication.RedirectFromLoginPage(txtUsern ame.Text, false);
}
else {
//error handling
}

GLobal.asax
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if ( Context.Request.IsAuthenticated ) {
string strUserName;
String strRoles;
String userName = String.Empty;

strUserName = Context.User.Identity.Name;
strRoles = EMS.PepSecurity.GetClientUsersGroups(strUserName);

string[] arrRoles = strRoles.Split('|');
Context.User = new GenericPrincipal( Context.User.Identity, arrRoles );
}
}

In the EMS.PepSecurity.GetClientUsersGroups function I am getting the error
on the following lines
string companyName = string.Empty;
try { companyName = HttpContext.Current.Session["CompanyName"].ToString(); }

The object cannot be found.

How can I save the company name if the session will not work?
Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Session is just that - only relevent for a specific users session, sounds
like you need to use the "Application" object to store this on, similar, just
different scope.

Dave

"danman226" wrote:
I will be using a companyname, user name, and password to authenicate users
in my system. I am trying to save the company name in the session for later
use. I cannot access the Session["CompanyName"] object in the
Application_AuthenticateRequest function. I need the companyname to lookup
the users group to build the GenericPrincipal for the user. My code is below.

Login Page:
int c = SiteSecurity.DBAuthenticate(txtCompanyName.Text, txtUsername.Text,
txtPassword.Text);
if (c > 0) {
//save the company name into the session
Session.Add("CompanyName", txtCompanyName.Text);
FormsAuthentication.RedirectFromLoginPage(txtUsern ame.Text, false);
}
else {
//error handling
}

GLobal.asax
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if ( Context.Request.IsAuthenticated ) {
string strUserName;
String strRoles;
String userName = String.Empty;

strUserName = Context.User.Identity.Name;
strRoles = EMS.PepSecurity.GetClientUsersGroups(strUserName);

string[] arrRoles = strRoles.Split('|');
Context.User = new GenericPrincipal( Context.User.Identity, arrRoles );
}
}

In the EMS.PepSecurity.GetClientUsersGroups function I am getting the error
on the following lines
string companyName = string.Empty;
try { companyName = HttpContext.Current.Session["CompanyName"].ToString(); }

The object cannot be found.

How can I save the company name if the session will not work?

Nov 19 '05 #2

P: n/a
Session is not yet bound to the context during Authenticate. You will need
to place this information in a cookie to persist it correctly.

bill
"danman226" <da*******@discussions.microsoft.com> wrote in message
news:16**********************************@microsof t.com...
I will be using a companyname, user name, and password to authenicate users in my system. I am trying to save the company name in the session for later use. I cannot access the Session["CompanyName"] object in the
Application_AuthenticateRequest function. I need the companyname to lookup
the users group to build the GenericPrincipal for the user. My code is below.
Login Page:
int c = SiteSecurity.DBAuthenticate(txtCompanyName.Text, txtUsername.Text,
txtPassword.Text);
if (c > 0) {
//save the company name into the session
Session.Add("CompanyName", txtCompanyName.Text);
FormsAuthentication.RedirectFromLoginPage(txtUsern ame.Text, false);
}
else {
//error handling
}

GLobal.asax
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if ( Context.Request.IsAuthenticated ) {
string strUserName;
String strRoles;
String userName = String.Empty;

strUserName = Context.User.Identity.Name;
strRoles = EMS.PepSecurity.GetClientUsersGroups(strUserName);

string[] arrRoles = strRoles.Split('|');
Context.User = new GenericPrincipal( Context.User.Identity, arrRoles );
}
}

In the EMS.PepSecurity.GetClientUsersGroups function I am getting the error on the following lines
string companyName = string.Empty;
try { companyName = HttpContext.Current.Session["CompanyName"].ToString(); }
The object cannot be found.

How can I save the company name if the session will not work?

Nov 19 '05 #3

P: n/a
Thanks.

I rewrote my forms authentication request to get it to work.

"William F. Robertson, Jr." wrote:
Session is not yet bound to the context during Authenticate. You will need
to place this information in a cookie to persist it correctly.

bill
"danman226" <da*******@discussions.microsoft.com> wrote in message
news:16**********************************@microsof t.com...
I will be using a companyname, user name, and password to authenicate

users
in my system. I am trying to save the company name in the session for

later
use. I cannot access the Session["CompanyName"] object in the
Application_AuthenticateRequest function. I need the companyname to lookup
the users group to build the GenericPrincipal for the user. My code is

below.

Login Page:
int c = SiteSecurity.DBAuthenticate(txtCompanyName.Text, txtUsername.Text,
txtPassword.Text);
if (c > 0) {
//save the company name into the session
Session.Add("CompanyName", txtCompanyName.Text);
FormsAuthentication.RedirectFromLoginPage(txtUsern ame.Text, false);
}
else {
//error handling
}

GLobal.asax
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if ( Context.Request.IsAuthenticated ) {
string strUserName;
String strRoles;
String userName = String.Empty;

strUserName = Context.User.Identity.Name;
strRoles = EMS.PepSecurity.GetClientUsersGroups(strUserName);

string[] arrRoles = strRoles.Split('|');
Context.User = new GenericPrincipal( Context.User.Identity, arrRoles );
}
}

In the EMS.PepSecurity.GetClientUsersGroups function I am getting the

error
on the following lines
string companyName = string.Empty;
try { companyName =

HttpContext.Current.Session["CompanyName"].ToString(); }

The object cannot be found.

How can I save the company name if the session will not work?


Nov 19 '05 #4

P: n/a
The way to solve this is to cache the user's role mappings in the ASP.NET
data Cache object. You can generate a key based upon the username and fetch
them that way. So, the Session isn't needed to cache that data.

-Brock
DevelopMentor
http://staff.develop.com/ballen
I will be using a companyname, user name, and password to authenicate
users in my system. I am trying to save the company name in the
session for later use. I cannot access the Session["CompanyName"]
object in the Application_AuthenticateRequest function. I need the
companyname to lookup the users group to build the GenericPrincipal
for the user. My code is below.

Login Page:
int c = SiteSecurity.DBAuthenticate(txtCompanyName.Text,
txtUsername.Text,
txtPassword.Text);
if (c > 0) {
//save the company name into the session
Session.Add("CompanyName", txtCompanyName.Text);
FormsAuthentication.RedirectFromLoginPage(txtUsern ame.Text, false);
}
else {
//error handling
}
GLobal.asax
protected void Application_AuthenticateRequest(Object sender,
EventArgs e)
{
if ( Context.Request.IsAuthenticated ) {
string strUserName;
String strRoles;
String userName = String.Empty;
strUserName = Context.User.Identity.Name;
strRoles = EMS.PepSecurity.GetClientUsersGroups(strUserName);
string[] arrRoles = strRoles.Split('|');
Context.User = new GenericPrincipal( Context.User.Identity,
arrRoles );
}
}
In the EMS.PepSecurity.GetClientUsersGroups function I am getting the
error
on the following lines
string companyName = string.Empty;
try { companyName =
HttpContext.Current.Session["CompanyName"].ToString(); }
The object cannot be found.

How can I save the company name if the session will not work?


Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.