C# - Which Session Method To Use When Removing?
Jul 16, 2010
I been using Session.clear() and I noticed in firecookie that the session still exists. So I started to google around and found there are 4 ways to remove a session
Session.Remove(strSessionName); Remove an Item from Session State Collection
Session.RemoveAll() Remove all items from session collection
Session.Clear() Remove all items from session collection Note: There is no difference between Clear and RemoveAll. RemoveAll() calls Clear(), internally.
Session.Abandon() Cancels the Current Session
Now clear and remove seem to do the same thing but which one should you be using like why use remove() over abandon over clear.
Like if you use session.Abandon it kills the current session. Where clear() removes the values.
Why would you only want to keep the session around with no values in it? Why not just kill it completely?
View 1 Replies
Similar Messages:
Feb 4, 2011
I've inherited an asp.net web solution, which has business logic and data calls as seperate assemblies. In the business layer there are a small number of calls to get/set HttpContext session values. I've looked around for an example that will allow me to abstract this away from the business logic as I'd like to be able to reuse these assemblies in non-web projects, could anyone please give me an example of the best way to do this. I was thinking of some sort of session factory that will obtain values from some sort of persistant store depending on the usage scenario but I'm new to architecture really and would appreciate a pointer or two.
View 3 Replies
Jan 16, 2011
I am using C#.
I am having below code in C#:
protected override void OnInit(EventArgs e)
{
try
{
if (Session["boolSignOn"].ToString() == "true".ToString())
{
lblPanelOpen.Text = Session["panelOpen"].ToString();
}
else
{
lblPanelOpen.Text = Session["panelOpen"].ToString();
}
}
catch (Exception ex)
{
Logger.Error("Error processing request:" + ex.Message);
}
}
protected override void OnLoad(EventArgs e)
{
try
{
if (!string.IsNullOrEmpty(Session["panelOpen"].ToString()))
{
lblPanelOpen.Text = string.Empty;
Session.Remove("panelOpen");
}
}
catch (Exception ex)
{
Logger.Error("Unable to remove the session variable:" + ex.Message);
}
}
In above code I am having a Session["panelOpen"] variable which is created from another user control and once my page is trying to render, I am storing Session["panelOpen"] in my hidden lblPanelOpen.Text on page OnInit() method, however when page is loaded completely then I am trying to remove the session variable.
View 4 Replies
May 31, 2010
Long ago, I created an ASPNET user for development use.However, every time I boot up my dev system, I'm presented with a user login for ASPNET, among others.I don't want to remove ASPNET; I need it for dev work.But how do I keep it from appearing among the list of User Logins available at boot-up?
View 4 Replies
Oct 29, 2010
I want to access the user session from a web method. But when I check for the session object, its nothing! How can I access the current user's session from the webmethod?
My code:
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _.......
View 2 Replies
Dec 18, 2010
I'm currently developing a website using .net MVC 3 and I'm on the authentication layer...Here is the scenario: user is logged with the "remember me" option checked : a user Session is created on the server as well as the authentication cookie on the client side.The Session timeout is set to 20 minutes.After 25 minutes of inactivity the user goes back onto the website and Session, now expired, does not exist anymore but the authentication cookie still exists
View 1 Replies
Mar 1, 2011
I am storing the returned sql resultant rows in a session variable ... so that I need not to query again and again
Session["ds"] = datasetname;
Everything is fine but when I am doing export to excel ... where at last after the export is completed I am calling the method in try/catch
try {
Response.End()
}
catch {}
But due to this, my session variable (ds) is getting expired and when I am using it next there is no rows and hence my page displays no data.
I tried going through internet and found that this is a bug it seems as identified by Microsoft and they have provided a hotfix for this but in Windows Vista .... I am running on XP.
[URL]
Is there any other workaround to this problem?
View 1 Replies
Mar 21, 2011
im trying to set up a session for UserID which is contained in the User table along with username and password. Im unsure how to get the UserID based on the username and password in my sqlsyntax then pass it to my session? My last peace of code is just a test in a label to see if it will pass the number to the label.
[code]....
View 1 Replies
Aug 18, 2010
I have a method in one class file with defination like this which gets the user id of logged person.
public string GetUserID(HttpRequest req)
{ .... }
I need to call this method in global.asax and save that value in session. I need to use this session value i need to use this Session value and assign that to label in Masterpage. I did not use global.asax before. And what should be the input to method... i have seen only Request is have the returntype HttpRequest. So i thought of giving that.
View 1 Replies
Apr 8, 2010
I'm trying to use SESSION in my MVC application.I wrote following line in Global.asax in Application_Start() method file:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
//uzupełnij zmienne sesyjne
HttpContext.Current.Session["LOCATION_ID"] = 15;
RegisterRoutes(RouteTable.Routes);
}
I also enabled SessionState in Web.config by addind following line:
<sessionState mode="InProc" cookieless="false" timeout="120" />
And when I run the application I'm getting this exception:
Szczegły wyjątku: System.NullReferenceException: Odwołanie do obiektu nie zostało ustawione na wystąpienie obiektu.
Błąd źrdła:
[Code]....
Wiersz 31: //uzupełnij zmienne sesyjneWiersz 32: Wiersz 33: HttpContext.Current.Session["LOCATION_ID"] = 15;Wiersz 34: Wiersz 35: RegisterRoutes(RouteTable.Routes);
View 5 Replies
Apr 13, 2010
I am creating an Asp.net web site which will support dynamic data. When I am creating a dynamic web site from Scratch (from template in VS) all is working fine. But when I am trying to add dynamic entity (.edmx) file and running the application I am getting following error
"The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'. "
View 2 Replies
Mar 5, 2011
At times when we access session["key"].To String() it gives exception as when session is expired and session variable is accessed. So I am in for extension method on object so that I could do it as session["key"].getString() so that every time I don't have to do Convert.ToString (session["key"])Other way solutions are also appreciable.
View 5 Replies
May 21, 2010
The following text coming from database. In that i need only content , and not needed script content. how can i remove script via c#.net? Leaving behind to mourn her loss are her loving husband Edward T. Safer Sr.; her sons Edward T. Safer Jr. and his wife Lori of Galloway and Robert J. Safer and his wife Doreen of West Milford; her daughter Ruth Ellen Ward and her husband Stan of West Caldwell; four sisters Doris Cabany and Renee McCoy of Grantville, Ga., Beverly Judge of Seattle, Washington and Margaret Graber of Pompton Lakes; ten grandchildren Samantha, Marissa, Rachel, Dylan, Casey, E.J., Kali, Robert, Shannon and Jonathan.
Funeral services will be held at the Vander May Wayne Colonial Funeral Home, 567 Ratzer Road, Wayne on Tuesday, February 23, 2010 at 10 AM. Friends may visit with the family at the funeral home on Monday, February 22nd from 2-4, 7-9 PM. Those planning an expression of sympathy in Ruth's memory are asked to consider The Passaic Valley Hospice, 783 N . Riverview Dr., Totowa, NJ 07512
<!-- slideshow --><div id="playerWrapper" style="width: 300px; height: 250px; background-color: #fefefe;"><div id="player_container"></div> </div> <script type="text/javascript" src="/JWImageRotator/swfobject.js"></script> <script type="text/javascript">
var s1 = new SWFObject("/JWImageRotator/imagerotator.swf", "rotator", "300", "250", "7");s1.addParam("allowfullscreen", "true"); s1.addVariable("showicons", "false");s1.addVariable("shownavigation", "false");s1.addVariable("file", "http://localhost:1659/portals/0/media/3363.xml");s1.addVariable("width",
"300");s1.addVariable("transition", "slowfade");s1.addVariable("height", "250"); s1.write("player_container");</script><!--end slideshow -->
View 2 Replies
Jan 25, 2010
Can you remove all javascript that is added by asp.net?
View 6 Replies
Feb 23, 2011
I am trying to get a simple multi-page program to run correctly. I have everything set up, except for the "remove" function. When I try to remove an item from the list box nothing happens. Insted of trying to explain it I will show you the code...
Index
Code:
[code]....
View 5 Replies
Jul 20, 2010
i have one dataset that populates some values like value1, value2, value3, value1, value3, etc. And i am showing this values in a dropdown list. But my requirement is that i have to show the same value once. That is the dropdown should be display like this, value1, value2, value3. Not repeat the existing value.
View 3 Replies
Dec 16, 2010
i have list<player> with duplicates.
i need to create another list<player> from the first list <player> with out any duplicates.
View 3 Replies
Jul 13, 2010
I want to remove particular from GridView when exporting to excel,
GridView1.Columns.RemoveAt(9);
exportToExcel(GridView1);
View 1 Replies
May 20, 2010
1 - If I insert to Cache by assigning the value:
Cache["key"] = value;
what's the expiration time?2 - Removing the same value from Cache:
I want to check if the value is in Cache by if(Cache["key"]!=null), is it better to remove it from Cache by Cache.Remove("key") or Cache["key"]=null ?
-- Edit --After having tried Cache.Remove and Cache["key"]=null, DO NOT USE Cache["key"]=null, as it will throw exceptions when used in stress.
View 4 Replies
Aug 20, 2010
I have Two datatables dtA,dtB ,both contains column name is "FiledName" I need to remove item
from dtA when same row data exists in dtB.
dtA dtB
A A
B F
C C
D Z
I want o/p like this
0/p
dtA
B
D
View 4 Replies
Sep 19, 2013
I am trying to achieve freezing the first column not to be scrollable horizontally and i am able to achieve but having two gridview inside a table with two td's. The problem what i ma facing is i am getting some space between two td's. attached the image for reference and below is the my code.
Code:
<asp:UpdatePanel ID="updReport" runat="server" style="margin-top:40px;">
<ContentTemplate>
<div id="divGrid">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="width: auto; vertical-align: top;">
[code].....
View 1 Replies
Oct 18, 2010
I have an ObjectDataSource that I want to perform updates using a business entity i.e. Type="Object"). Since the values for the entity are within a user control, I have stored a reference to the control in Session and in the updating event, set the new instance to the value of the entity from the user contol property (which also pulls values from the form viaother properties of the control):
Protected Sub MasterDataSource_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles MasterDataSource.Updating
Dim entity As New Login()
Dim accountControl As AccountInfo = TryCast(Session("AccountCtrl"), AccountInfo)
entity = accountControl.Entity
e.InputParameters.Add("entity", entity)
End Sub
And here's the markup for the datasource:
<asp:ObjectDataSource ID="MasterDataSource" runat="server" EnableCaching="true" CacheDuration="10"
SelectMethod="SelectAll" UpdateMethod="Update" TypeName="Data.DAL.LoginDAL">
</asp:ObjectDataSource>
My question is, how can I get the update method to pass this entity to the update method in my BLL class? It seems the Update method requires an ID or reference to the original object to use in determining whether any changes have taken place, but I don't really want to do this. In other words, I just want to use the Update event on my ObjectDataSource to pass my entity to the method ("Update") I set as a property and then let this business method handle the update of the data. Shown below, is the BLL update method I want to call:
Public Overloads Function Update(ByVal entity As Login)
If entity Is Nothing Then
Throw New ArgumentNullException("entity")
End If
MyBase.Update("UpdateLogin", entity.Username, entity.Password, entity.FirstName, entity.LastName, entity.Role, entity.Region, _
entity.Email, entity.Title, entity.TierID, entity.Street, entity.City, entity.State, entity.Zip, entity.Mobile, entity.Phone, entity.Fax)
End Function
When I try to call this as it stands now, I get an error: ObjectDataSource 'MasterDataSource' could not find a non-generic method 'Update' that has parameters: ID, entity. Previously, I'd set up a long list of parameters of basic data types (string, int, boolean), but this is rather cumbersome and I was hoping to use an entity for this (FYI, I also got the same type of error when I tried this approach, but with the ID as the
last parameter in the list). Perhaps what I'm doing here is atypical to how the ODS is normally used?? Has anyone done something like this successfully?
View 1 Replies
Aug 26, 2010
I have an application that has JS calling ASMX files to do asyncronous requests, using ASP.NET AJAX.
The problem is that I use always the same "onError" function, and now I don't know how to identify the method that rised the error, and it is giving me a lot of problems to debug errors. The parameter "data" of the onError method does not give enough information, for
example:
en System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
en System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)
en System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)
en System.Web.Script.Serialization.ObjectConverter.ConvertObjectToType(Object o, Type type, JavaScriptSerializer serializer)
en System.Web.Script.Services.WebServiceMethodData.StrongTypeParameters(IDictionary`2 rawParams)
en System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary`2 parameters)
en System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)
en System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)
Is there any way to know the webmethod that raised the error?
View 1 Replies
Dec 15, 2010
I don't know what I'm making wrong.I have a submit button, and on click it should execute the funktion in the code behind, but I get the error that the funktion is undefined.this is my code in the .aspx webform:
<%@ Page Language="C#" AutoEventWireup="True" MasterPageFile="~/DashMaster.master" CodeBehind="BI_MDR.aspx.cs" Inherits ="BI_MDR.StoredProc"%> [code].......
View 2 Replies
Feb 8, 2010
I want to create a web method that accepts a List of custom objects (passed in via jQuery/JSON). When I run the website locally everything seems to work. jQuery and ASP.NET and everyone is happy. But when I put it on one of our servers it blows up. jQuery gets a 500 error after the ajax request with the response being:
System.InvalidOperationException: EditCustomObjects Web Service method name is not valid.
[WebMethod]
public void EditCustomObjects(int ID, List<CustomObject> CustomObjectList)
[code]...
View 8 Replies