Yorkshire Divers

Deep Blue Technical
Go Back   YD Scuba Diving Forums > Non-Diving Related Forums > Technology
User Name
Password

Welcome to the YD Scuba forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

Technology: Discuss C# .NET - Session variables inside an abstract class in the Non-Diving Related Forums forums: OK, so am not sure if this is the problem, but I have an abstract class in my web application ...

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 23-08-06, 09:22 AM
MartinS's Avatar
MartinS MartinS is offline
Senior Member
 

Join Date: Jul 2002
Location: Redhill, Surrey
Posts: 1,550
MartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the sea
C# .NET - Session variables inside an abstract class

OK, so am not sure if this is the problem, but I have an abstract class in my web application called utilities, and whilst working on the application, have been asked to simplify the existing code and remove any duplication (of which ther is lots!). First thing I have worked on is report creation - there are seven reports and each one uses the same (or very similar) layout for page design, so I have moved all the code to a public static routine inside the utilities class.
Now, the problem is that all the code does is read session variables and write them to a streamwriter, but within the class, I cannot get access to the Session (System.Web.SessionState) keyword and it will not let me compile. The only option is to pass these session variables to the procedure, but I cannot see why - can anyone shed some light on why I cannot access 'session'?
Hope this makes sense!
Martin
__________________
Never test the depth of the water with both feet!
69 Divers SAC
Yorkshire Divers
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 23-08-06, 09:28 AM
BigHairyAl's Avatar
BigHairyAl BigHairyAl is offline
Mostly Harmless
 

Join Date: Jan 2006
Location: Leeds
Posts: 253
BigHairyAl paddles in the seaBigHairyAl paddles in the seaBigHairyAl paddles in the seaBigHairyAl paddles in the seaBigHairyAl paddles in the seaBigHairyAl paddles in the seaBigHairyAl paddles in the seaBigHairyAl paddles in the seaBigHairyAl paddles in the seaBigHairyAl paddles in the seaBigHairyAl paddles in the sea
Hmmmmm. The only reason I can't normally access 'session' (pub.beer.session) is because 'wife' (front.door.blocking) demands all my CPU time.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 23-08-06, 09:30 AM
RonProwse's Avatar
RonProwse RonProwse is offline
why does it always do that......
 

Join Date: Feb 2006
Location: Chatham
Posts: 520
RonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold water
what error do you get when you compile, i would think that due to the class being static it will not be able to access the session info, can you not change the interface of the static methods and pass the objects to the static class from the calls, or am i wide of the mark here.

Ron
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 23-08-06, 09:44 AM
MartinS's Avatar
MartinS MartinS is offline
Senior Member
 

Join Date: Jul 2002
Location: Redhill, Surrey
Posts: 1,550
MartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the sea
Quote:
Originally Posted by RonProwse
what error do you get when you compile, i would think that due to the class being static it will not be able to access the session info, can you not change the interface of the static methods and pass the objects to the static class from the calls, or am i wide of the mark here.

Ron
Ron
For each reference to the Session["key"], I get
"The name 'Session' does not exist in the class or namespace 'KP2.Utilities'"

I have added a using to System.Web, and my current solution is to pass all the session variables as parameters to the static procedure, but I was just hoping to do all the repetion in the routine rather than just pass in all the info each time.
Currently, my call and procedure looks like this:
Code:
vWriter = Utilities.WriteReportTitles( "Market Analysis", strCodesTitle, vTitles1, vTitles2 );
 
public static StreamWriter WriteReportTitles( string aReportTitle, string aCodesTitle, string aTitles1, string aTitles2 ) {

MemoryStream vStream = new MemoryStream();
StreamWriter vWriter = new StreamWriter( vStream );
// initialise string to show report title
vWriter.WriteLine( aReportTitle );
// add blank line
string pReportText = string.Empty;
vWriter.WriteLine( pReportText );
// add other elements of title one by one 
pReportText = "Base Date: " + Session["strDisplayEffDate"].ToString();
vWriter.WriteLine( pReportText );
pReportText = "Market Cut: " + Session["strCompanyGroupDescription"].ToString();
vWriter.WriteLine( pReportText );
pReportText = "Jobs: " + aCodesTitle;
vWriter.WriteLine( pReportText );
pReportText = "Locations/regions: " + Session["strRegionsTitle"].ToString();
vWriter.WriteLine( pReportText );
pReportText = "Regional Pay Factor: " + Session["RegionalPayFactor"].ToString() + "%";
vWriter.WriteLine( pReportText );
pReportText = "Aging Factor: " + Session["AgingFactor"].ToString() + "%";
vWriter.WriteLine( pReportText );
pReportText = "Run on: " + DateTime.Now.ToLongDateString();
vWriter.WriteLine( pReportText );
// add first line to column titles
vWriter.WriteLine( aTitles1 );
// add second line of column titles
vWriter.WriteLine( aTitles2 );
// return stream
return( vWriter );
}
If I then change the procedure to be non-static, then I also get the following error against the call:
An object reference is required for the nonstatic field, method, or property 'KP2.Utilities.WriteReportTitles(string, string, string, string)'

I hope this makes more sense
Martin
__________________
Never test the depth of the water with both feet!
69 Divers SAC
Yorkshire Divers

Last edited by MartinS : 23-08-06 at 09:59 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 23-08-06, 09:45 AM
MartinS's Avatar
MartinS MartinS is offline
Senior Member
 

Join Date: Jul 2002
Location: Redhill, Surrey
Posts: 1,550
MartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the sea
Quote:
Originally Posted by BigHairyAl
Hmmmmm. The only reason I can't normally access 'session' (pub.beer.session) is because 'wife' (front.door.blocking) demands all my CPU time.
Very good
__________________
Never test the depth of the water with both feet!
69 Divers SAC
Yorkshire Divers
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 23-08-06, 10:20 AM
RonProwse's Avatar
RonProwse RonProwse is offline
why does it always do that......
 

Join Date: Feb 2006
Location: Chatham
Posts: 520
RonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold water
as this is asp.net why not add Trace="true" to the end of the <%@ Page line (HTML) this will allow you to see the all the session values for the page other that than that i cant see an answer without all the code, but one place i will direct you to is the
GotDotNet: The Microsoft .NET Framework Community
post the question or search the ASP.NET forum.

Ron
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 23-08-06, 12:23 PM
MartinS's Avatar
MartinS MartinS is offline
Senior Member
 

Join Date: Jul 2002
Location: Redhill, Surrey
Posts: 1,550
MartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the sea
Ron
I have resolved it by adding a new class to do the job, and using some get properties to read the session variables where required. I think the problem is that the class is not an asp class, just a standard class, i.e. it does not reside behind a ASP web page.
Thanks anyway for your time, and also the link.
Thanks again
Martin
__________________
Never test the depth of the water with both feet!
69 Divers SAC
Yorkshire Divers
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Sponsored Links

Yorkshire Divers - RSS Feed
All times are GMT +1. The time now is 10:37 PM.
Powered by vBulletin
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.0.0 RC6
Trademark and all rights reserved : © YD.com Ltd (2006)
YD.com Ltd (Registered in England - 05886696)
Other sites : Golf Clubs | New Premiership Football Kits | MP3 Portable Players | MP3 Players For Sale | Replica Football Kits

Forums Directory