Class Access Session Object But Not When Deploying It To Server?
Mar 16, 2011
I have a custom MembershipProvider that I'm using in an ASP.NET 2.0 application. Inside of the class that extends membership provider, I have a function called AttemptLogin() that sets session variables if the user is valid. Inside that function, are a number of session variable assignments similar to the following:
HttpContext.Current.Session["id"] = "12345";
AttemptLogin() is being called by the Application_BeginRequest function in global.asax. This code works fine when I open it in visual studio, and then run it in the built-in development server by clicking "Start Debugging". However, when I deploy it to our testing server (Windows 2003 Server 64-bit running IIS in 32-bit mode), execution breaks when it reaches the code above, giving me the following message:
[NullReferenceException: Object reference not set to an instance of an object.]
CustomMembershipProvider.AttemptLogin() in c:InetpubwwwrootJoshApp_CodeCustomMembershipProvider.cs:1097
ASP.global_asax.Application_BeginRequest(Object sender, EventArgs e) in c:InetpubwwwrootJoshGlobal.asax:14
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
How can I access the session state successfully in this situation? Why does it work locally and not on the server?
View 2 Replies
Similar Messages:
Oct 29, 2010
I am implementing a custom membership and role providers where I need to store all the role/membership information in the user's session.
I am implementing these custom providers inside a class library project (different from the website project) and need to access the session in them. The idea is to store the role/membership related information in the session after retrieving them for the first time from the database.
When I try to access the Session using System.Web.HttpContext.Current.Session
I get this as a null object (Object reference not set to an instance of an object.
Why is the session turning out to be null?
View 1 Replies
Aug 31, 2010
I have my Website Application [URL]. How is it deploy my site to web server [ IIS ] so that it can be accessed via intranet.
View 1 Replies
Feb 15, 2010
I have a profile object in session with profile information for the currently logged in user. I wand to be able to inject it into my business classes so I can do validation etc in them without having to pass it in the parameter list in every method.
I have tried something like this in my ninject module:
Profile profile = HttpContext.Current.Session["Profile"] as Profile;
Bind<Profile>().ToConstant(profile).InTransientScope();
However it blows up with null reference when I do Kernel.Get() in my aspx. The BusinessObject takes a profile via the constructor. If I hard code the profile instead of using the HttpContext then everything seems to work. Not sure if ToConstant is the way to go, I am really looking for something that will get evaluated every time a new BusinessObject is created.
UPDATE
It seems that asking for injection to happen on a page level object inline is too soon for the session collection to be available. If I move in the Kernel.Get call to Page_Load it works just fine.
View 4 Replies
Jun 30, 2010
my solution currently has a website project and a class library project. I am attempting to access a session object from my class library but it is always returning null. In a settings class in my class library I store these values like so:
private static SessionProperty<WebUser> _currentUser = new SessionProperty<WebUser>("CurrentUser", delegate { return new WebUser(); });
public static WebUser CurrentUser
{
get { return _currentUser.Value; }
set { _currentUser.Value = value; }
}
I can access this just fine from any aspx page codebehind like so:
Settings.CurrentUser.User.ProviderUserKey.ToString();
However, if I attempt to do the same thing from a class in my classlibrary project it always returns null.
View 5 Replies
Jan 18, 2010
I have a page, Default.aspx, with its own code-behind file like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
public int[] anArray;
}
What I'd like to do is access to "anArray" from a C# class (not tied to a page) declared in App_Code folder. What can I do?
Edit: As said in the first comment, I really apreciate your about refactoring my connection objects. However, what I'm really doing here is to rewrite an old PHP application in order to get comfortable with basic C# and ASP.NET, so this code will never go really live. So, I'm still intersted in a way (if any) to access an object declared in a code-behind code from a standard C# class.
Edit2: I removed the OdbcConnection object in order to focus to the real problem: how to refer to an object istantiated in a code-behind file from a C# class situated in App_Code?
View 4 Replies
Mar 25, 2011
store our DAO objects in the Application object, so there's one object of each available for the whole application.
This Application object is easily accessed in the Page codebehind itself, but how do we access it from a plain class that is not extending anything?
View 1 Replies
Nov 15, 2010
In the VS2005 environment, when I test my session to make sure the page redirects to the main page (itself) if the session is null, it works. There is no error.
The function I use for this is:
[code]....
However, when it is in the production environment in IIS 6.0, when the session has timed out, and I then do a postback by doing some slider control, I see the page reload but immediately thereafter, it throws a Server Error exception of : Object reference not set to an instance of object.
Looking at the stack trace, the event occured:
AJAXEnabledWebApplication1._Default.Slider1_TextChanged(Object sender, EventArgs e)
however, why is it that the Slider1_TextChanged event fired even even after during page_load, the page was told to do a response.direct ?? shouldn't the entire page have gone through a full-page refresh life cycle ? why did it continue on to attempt to raise the Slider1_TextChanged event?
View 1 Replies
Mar 28, 2010
I'm having a problem with a class library I'm building. I have a class called Users and inside this class I have a property called UserInfo that is an object. Both of the classes Users and UserInfo are built using MyGenerations dOOdads. When I create an object instance of the Users class I am able to access the UserInfo property without a problem in my Windows App, however when I using the same library in a website the UserInfo property continues to return a no reference error. Like I said when running it in a WinApp I have no problems at all, I can access the UserInfo property and likewise all of UserInfo's properties. I am also having problems trying to debug the library using the website. And again I have no problems when using the WinApp. The way I've set it up is I have the Class library project open, and then I add the WinApp project and then the website project. When I set the WinApp as the startup project and run it I have no problems, I can set breakpoints and step through the code no problem. But when I set the Website as the startup project and try to debug I get a massage saying the breakpoint won't be hit. I then do what it tells me and right click on the breakpoint and set the location to allow the source to be different. This lets me hit the breakpoint, but every time I hit F10 to step I get "There is no source code available for the current location." For every step I take. This is making it really hard for me to figure out what going on with the code in the website. Sorry for the lengthy explanation. Here's the Users class, again it works great in the WinApp, just not the website.
[Code]....
View 6 Replies
May 27, 2012
I am trying to develop logic to add dynamic controls to page via class method. So I want to know how can we access the ASP.Net Page object reference in class method.
View 1 Replies
Feb 8, 2010
Is that possible to get access to Session, Cache, Server.MapPath() from a class in App_code?
View 1 Replies
Jul 2, 2010
I have a Dynamic Data application to which I have added a class for extending EDM. Everything works great, but now I am trying to set an entity property value equal to a value in session state - and its not recognizing the Session command. I'm trying to do something like this:
audit.action_by = CStr(Session("person_name"))
I think this is because I do not have the class Inheriting Page, but if I do add Inherits Page it breaks other stuff. How can I have the class include the ability to utilize sessions directly without inheriting Page?
View 2 Replies
Mar 27, 2010
How to access session variable in the class?
View 5 Replies
Jan 13, 2010
I built a base controller class inherits from Controller class to add some custom behavior to all controllers which will inherit from this base class.
My issue is when I try to access HTTPContext and Session objects in my custom base class, they are always null.
Am I doing something wrong or need missing something?
My custom base class definition:
public class ApplicationControllerBase : Controller
controllers classes definition:
public class HomeController : ApplicationControllerBase
using ASP.NET MVC 1, .NET 3.5.
UPDATE:
It seems the issue is I try to access HTTPContext in the constructor while HTTPContext is not ready yet, I tried it in the OnActionExecuted event handler and it works fine.
My question is what is the best place to access Session object in my custom controller class, that will guarantee executing my code with all controllers.
View 3 Replies
Mar 30, 2010
I am stuck with the issue of concurrent access to Session object. Actually my problem is i m writing to session in frame1 and trying to access that same Session object at the same time in Frame2's Page. I know about the reader/writer lock. I made the enablesessionstate = readonly in the page where i m writing to session. its giving me strange behavior on IE and firefox.
Its working concurrently in IE8 ( means page2 is diplaying modified values while page1 is changing the session object) but does not work in Firefox even page load is not called untill function on page 1 completed. Either anyone can fix my issue with firefox or there is new solution to reader/writer lock so that i can read the session at the same time while writing.
View 2 Replies
Mar 15, 2011
recommend a data access class / helper class for Access databases, similar to the sqlhelper class found in the (Data Access Application Block)?
View 6 Replies
May 10, 2010
Is it safe to access asp.net session variables through static properties of a static object?Here is what I mean:
public static class SessionHelper
{
public static int Age
{
get
{
[code]...
Is it possible that userA could access userB's session data this way?
View 2 Replies
Oct 27, 2010
I am storing a custom "Organisation" object as a session variable. One of the properties of the Organisation object is "OrganisationID" (integer). I have a DataSource that requires a parameter value to run, and I want to use a SessionParameter to populate this. In a previous version, I stored the OrganisationID directly as a session variable. In that case, I could easily access it like this:
[Code]....
However, how do I now access the OrganisationID property of an "Organisation" type session variable (called "Organisation")? I have tried this, which does not seem to work: <asp:SessionParameter Name="OrganisationID" SessionField="Organisation.OrganisationID" Type="Int32" />
View 2 Replies
Jan 28, 2011
I have a separate environment for development. On my production server, where we mostly host web applications, we deploy the precompiled version of the web project. While doing development I work on three projects. One is the WCF Service. Two, is the class library project. This library has classes which makes calls on the WCF service. And the third, is a web project which consumes the class library.
The last two projects come under one VS solution. I host the wcf service in the development environment. This service is added as service reference to my class library. I am unable to visualize what will happen once I add the DLL (viz output of the class library project) to my web project, and, the web project has to be deployed. At the time of deployment I have to change the service reference (the url of the svc file will change as it has to point to the production wcf service). How to go about this? What must I take care when adding the dll to the web project?
View 3 Replies
Dec 15, 2010
I need to access post and get variables inside a server control class, there is no access to Request object in server control class...
View 1 Replies
Jan 21, 2010
Is it possible to either access the properties, such as 'url', of a embedded media player object server side to change them? Or possibly dynamically create a new media player object with a different 'url' each time?
I am trying to change the property based off of a selectedindexchanging event of a gridview object.
View 2 Replies
Aug 30, 2010
I've scenario where I want to insert data into database without post back. there are around 12 to 13 fields which i need to insert. I'm passing DTO from the client side which is actually Json object. Now the problem which i'm facing is how to convert that Json object which i got in webservice to the "class" (in my case class name is User) object.
[Code]....
In the above case AddNewUser method takes the object of User class. But i'm getting casting error. So how do I convert Json object to the "User" class object?
View 3 Replies
Aug 16, 2010
My Session gets null after redirecting to other page,
Below written is my code in login page:
protected
void btnLogin_Click(object
sender, ImageClickEventArgs e)
{
// saving login history calling submit function to save login details in database
callsubmitfunctionofDatalayer();
//saving session
Session["Username"] = txtUsername.Text;
[Code]....
View 3 Replies
May 7, 2010
I have application variable in global.asax like
[Code]....
I wnat to aacess this path with images in aspx(design-source) side. I successfully tested this with html controls but it contains error with server controls here is the aspx content
[Code]....
Problem result is
[Code]....
View 1 Replies
Jul 20, 2010
I have an existing class for an input, is it possible to add an additional class for the object in C#.net, instead of doing a if/else and not having a preset class on the object in the first place?
View 3 Replies