C# - Session Is Null When Inherit From System.Web.UI.Page?
Jun 16, 2010
I want to extend the System.Web.UI.Page-class with some extra stuff.
In the ctor I need the value of a session-variable.
The problem is that the Session-object is null...
public class ExtendedPage : System.Web.UI.Page {
protected foo;
public ExtendedPage() {
this.foo = (int)HttpContext.Current.Session["foo"]; // NullReferenceException
}
}
If I move the part with the session-object into the Load-Event everything works fine...
public class ExtendedPage : System.Web.UI.Page {
protected foo;
public ExtendedPage() {
this.Load += new EventHandler(ExtendedPage_Load);
}
void ExtendedPage_Load(object sender, EventArgs e) {
this.foo = (int)HttpContext.Current.Session["foo"];
}
}
Why is the Session-object null in the first case??
View 2 Replies
Similar Messages:
Apr 4, 2011
I am developing a website which will be having both asp.net pages and MVC pages in it, So I have BaseWebPage class which will be used for both asp.net pages and MVC Views. but My BaseWebPage class is inherited from System.Web.Mvc.ViewPage, So Will there be any code/ functionality break for normal asp.net pages, because System.Web.Mvc.ViewPage is overriding some of the Pagelife cycle methods.
View 1 Replies
Jun 15, 2010
I need to refresh my webpage in case of a change in the system time. However I see that my session variables are becoming null when the system time changes. So I cannot perform the refresh action since my webpage requests a login.I am not setting the Session variables to null explicitly anywhere in the code. I can't seem to figure out how they are becoming null.
View 6 Replies
Dec 23, 2015
If you click a button that takes you to a page using <a href....> is the session variable lost?
In VS testing the web app everything works perfect, but when it is pushed to production when the page is loaded the Session Variable is null?
View 1 Replies
Oct 18, 2010
Recently, I tried to get my Web Service class to inherit from a custom base class that inherits from System.Web.Services.WebMethod instead of the System.Web.Services.WebMethod directly.
However, I've been getting Error 500.
Public Class Service1
Inherits BaseClass
<System.Web.Services.WebMethod()> _
Public Function GetSessionID() As String
GetSessionID = Me.Session.SessionID
End Function
End Class
public class BaseClass
Inherits System.Web.Services.WebService
public property Property1 as string
public property Property2 as string
End Class
View 6 Replies
Aug 4, 2010
I have logged in to the application and naviagate to Resource Editor page where it allows user to enter the value and saves to the resource file of the application.
After user clicks save button and navigate to different page the session value becomes null.
If the user navigate to different page without clicking save the session variable has its value
View 3 Replies
Jun 10, 2010
Im trying to use code provide in this link below.http://www.codeproject.com/KB/aspnet/MultipleTabWindows.aspxim trying to have the below code in my master page instead of adding to each page. it works if i add to each page, but when i add to ,master page the session value for "WindowName" is always null.how can i fix this?
<script language="javascript" type="text/javascript">if(window.name != "<%=GetWindowName()%>"){ window.name = "invalidAccess"; window.open("InvalidAccess.aspx", "_self");}</script>public string GetWindowName(){ return Session["WindowName"].ToString();}
View 6 Replies
Jun 4, 2010
Ive created an object and placed it in the session, then in my .ashx handler I want to get that object from the session. The problem is that its always null !
heres how ive placed the object into the session from an aspx page
[Code]....
View 4 Replies
Apr 4, 2011
I'm storing a token in a session variable. I launch a report that needs this token in a new ASPX page by using the javascript windows.open function. When this new page loads the HttpContext.Current.Session is null.I have gotten around this by passing the token in the query string but activity in this window needs to keep the session of the parent window active and I'm not sure what the session object being null means for this scenario.
View 3 Replies
Sep 7, 2010
i have 2 page,
1.login.aspx --- 2.welcome.aspx
in my login.aspx im storing username into sesssion as below:
Session["usernm"] = txtUsername.Text;
in my welcome.aspx page
in page_load event
if (Session["usernm"]==null)
{
Response.Redirect("Login.aspx");
}
here if i manulally paste the url ( http://localhost:4125/Loginado/welcome.aspx) it should go to login.aspx for user credentials
but its going directly to welcome.aspx page.
View 5 Replies
Mar 18, 2010
I have a problem with a SessionVariable. I will explain what is happening:
1. From the default.aspx I send Session["LoginByAdmin"] = "Dummy"; and then redirect to this page where I have the code below. So the Page_Load sees that this Session["LoginByAdmin"] != null and enter this page. This works fine !
2. In the Page_Load, I later fill a ListBox1 with foldernames.
3. With Button1_Click1, I will now delete the choosen Folder in the ListBox1 wich works fine the first time and the ListBox updates the new existing folders in the ListBox. (I have wrapped this inside an updatepanel)
The problems comes now when I try to delete a choosen folder in the ListBox1 the second time in a row. When I select a Folder in the ListBox1 and now Press Button1, I will be redirected to "Default.aspx". This meens that this code is running: (That meens that Session["LoginByAdmin"] == null and I have not set this to null anywhere. This is my big question how this variable can be = null here?
if (Session["LoginByAdmin"] == null)
Response.Redirect("Default.aspx");
break;
[Code]....
View 5 Replies
Jul 29, 2010
I have some cascading dropdownlists using the ajax toolkit I have a set up datatables in an xsd file. Then use these in a webservice to populate all the fields ... this all works great but now i need to pass an additional paramter to the first dropdownlist ( a date) but don't know how to do this? The method is below...
[Code]....
The other code is:
[Code]....
The first change would be to the tableadapter to add a param to the code i.e
AuditWebDS.TeamsDataTable teams = teamsAdapter.GetTeams(calldate);
but how do i get the calldate param to the webservice method... i tried a session variable but it comes up with session is null ? Is there another better way?
View 1 Replies
Apr 26, 2010
So I've read quite a few posts about how to do this, and it's still getting me. I'm trying to control access to a directory, but I continue to get a null session error. I'm doing my check in PostAcquireRequestState
[Code]....no matter where I put this, my session always comes back null. I am using IRequireSessionState on the class as well. Am I pulling the context wrong?
View 6 Replies
Feb 8, 2011
I created a page to be the base Page in my web application to add inside it some common functionality. but when I try to inhirite from it then VS gives me the following error:
The type or namespace name 'CentralPage' could not be found(are you missing a using directive or an assembly reference?)
Note: I just want code-behind functionality in the base page.
What should I do ?
View 2 Replies
Aug 10, 2010
I have been trying to find a way to declare two classes using page directive, but it seems like mvc framework doesnt support it.
I have got :
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<ContactManager.Models.contact>>" %>
which shows the list of the contacts including edit delete and create option.
What I need to declare another model class which is FileRepository.cs for uploading files on the same page. In this case the page directive should be like:
2. <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<ContactManager.Models.FileDescription>>" %>
Is there any way I can incorporate both into one as the first is coming from the database.
View 6 Replies
Dec 15, 2010
Is it possible to inherit a page events to another page
like inherit page Init to another page...
View 2 Replies
Oct 23, 2010
I have Page, MasterPage and UserControl in my project.
So I create basepage class and share some logic, then inherit from System.Web.UI.Page. My problem is I want use single basePage for any type of UI content.
View 1 Replies
Jun 2, 2010
Can a page inherit multiple master pages?(ASP.NET)
View 4 Replies
Jan 20, 2011
I want to know, how to inherit a class within the form/page?
View 4 Replies
Apr 29, 2010
Can I Inherit a view of Asp.net mvc2 from normal asp.net master page
View 1 Replies
Jul 30, 2010
this is my tipical page
as you can see, i have a connection property and a function who return if the program can connects to DB with any error
[Code]....
i want optimize my codei discovered that i must use connect() function in every page,i am thinking to creare a class who have connection property and connect() method and derive my page to it, is it a good idea?
View 7 Replies
Apr 29, 2010
Can I Inherit a view in asp.net mvc2 from normal asp.net master page
View 2 Replies
Jan 12, 2011
I was trying to read a data of a Job stream using a System.Printing name space, from a default print queue. I can get all the job info, like number of pages, but the JobStream data is always null, is there a solution for that? or is it broken or a bug. Here is my code
foreach (PrintSystemJobInfo
Job in
defaultPrintQueue.GetPrintJobInfoCollection())
[code]...
View 1 Replies
Apr 26, 2013
I have made a web page in which there is login screen when user login it goes next page but my problem is if i directly enter the url of that page it open. I want it should not open unless the user log in...Â
View 1 Replies
Jul 21, 2010
My designer.cs file of all the SQL tables is generated by LINQ-TO-SQL. The class and attribute in question is like this.
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Transfers")]
public
partial
class
Transfer :INotifyPropertyChanging,[code]...
I need to assign a null to the attribute so that the value 0 does not get save to the database.
View 2 Replies