Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Application Page - session state doesn't work(?)

$
0
0

Hello,

I have to create a solution with multiple application pages between which you shall be able to navigate through. For saving the selection of a listbox during the navigation onto another application page I thought of using the session state service.

Therefore I activated it and adapted my web.config accordingly.

Now it doesn't seem to work with my code - maybe related to my code or the web.config(?). There doesn't seem to be any value stored in the session-store - or maybe it only can't be received from it(?).

my code is:

aspx:

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server"><asp:ListBox runat="server" ID="projektliste" SelectionMode="Single" OnSelectedIndexChanged="projektliste_OnSelectedIndexChanged" AutoPostBack="True"/><asp:TextBox runat="server" ID="test"></asp:TextBox></asp:Content>

aspx.cs:

using System;
using System.Web;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;


namespace besprprot.Layouts.besprprot
{
    public partial class navigation : LayoutsPageBase
    {
        public string server = "https://testserver/";
        public void Page_Load(object sender, EventArgs e)
        {
            fill_projektelist();
        }

        public void fill_projektelist()
        {
            projektliste.Items.Clear();
            using (SPSite oSite = new SPSite(server))
            {
                using (SPWeb oWeb = oSite.OpenWeb())
                {
                    SPList oList = oWeb.Lists["projekte"];
                    SPListItemCollection oCollection = oList.Items;
                    foreach (SPListItem oItem in oCollection)
                    {
                        if (oItem["gz"].ToString() != "" && oItem["gz"].ToString() != String.Empty)
                        {
                            projektliste.Items.Add(oItem["gz"].ToString());
                        }
                    }
                }
            }
            if ((string)Session["gzauswahl"] == null || (string)Session["gzauswahl"] == String.Empty)
            {
                test.Text = "keine Sessionvariable vorhanden";
            }
            else
            {
                projektliste.SelectedValue = (string) Session["gzauswahl"];
                test.Text = Session["gzauswahl"].ToString();
            }
        }


        public void projektliste_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            if ((string)Session["gzauswahl"] == null || (string)Session["gzauswahl"] == String.Empty)
            {
                Session["gzauswahl"] = projektliste.SelectedValue;
                test.Text = (string)Session["gzauswahl"];
            }
            else
            {
                Session["gzauswahl"] = null;
                Session["gzauswahl"] = projektliste.SelectedValue;
                test.Text = (string)Session["gzauswahl"];
            }
        }
    }
}

Here is my web.config in case I misconfigured something. I only posted the relevant areas of the file:

<httpModules><add name="FederatedAuthentication" type="Microsoft.SharePoint.IdentityModel.SPFederationAuthenticationModule, Microsoft.SharePoint.IdentityModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /><add name="SessionAuthentication" type="Microsoft.SharePoint.IdentityModel.SPSessionAuthenticationModule, Microsoft.SharePoint.IdentityModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /><add name="SPApplicationAuthentication" type="Microsoft.SharePoint.IdentityModel.SPApplicationAuthenticationModule, Microsoft.SharePoint.IdentityModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /><add name="SPWindowsClaimsAuthentication" type="Microsoft.SharePoint.IdentityModel.SPWindowsClaimsAuthenticationHttpModule, Microsoft.SharePoint.IdentityModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /></httpModules><pages enableSessionState="true" enableViewState="true" enableViewStateMac="true" validateRequest="false" clientIDMode="AutoID" pageParserFilterType="Microsoft.SharePoint.ApplicationRuntime.SPPageParserFilter, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" asyncTimeout="7"></providers></roleManager><sessionState mode="SQLServer" timeout="60" allowCustomSqlDatabase="true" sqlConnectionString="Data Source=SPDB;Initial Catalog=SessionStateService_087bf28fb189412789826d60b9d3a7ae;Integrated Security=True;Enlist=False;Pooling=True;Min Pool Size=0;Max Pool Size=100;Connect Timeout=15" /></system.web><system.webServer><modules runAllManagedModulesForAllRequests="true"><remove name="AnonymousIdentification" /><remove name="FileAuthorization" /><remove name="Profile" /><remove name="WebDAVModule" /><remove name="Session" /><add name="SPNativeRequestModule" preCondition="integratedMode" /><add name="SPRequestModule" preCondition="integratedMode" type="Microsoft.SharePoint.ApplicationRuntime.SPRequestModule, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /><add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /><add name="SharePoint14Module" preCondition="integratedMode" /><add name="StateServiceModule" type="Microsoft.Office.Server.Administration.StateModule, Microsoft.Office.Server, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /><add name="PublishingHttpModule" type="Microsoft.SharePoint.Publishing.PublishingHttpModule, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /><add name="DesignHttpModule" preCondition="integratedMode" type="Microsoft.SharePoint.Publishing.Design.DesignHttpModule, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /><add name="FederatedAuthentication" type="Microsoft.SharePoint.IdentityModel.SPFederationAuthenticationModule, Microsoft.SharePoint.IdentityModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /><add name="SessionAuthentication" type="Microsoft.SharePoint.IdentityModel.SPSessionAuthenticationModule, Microsoft.SharePoint.IdentityModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /><add name="SPWindowsClaimsAuthentication" type="Microsoft.SharePoint.IdentityModel.SPWindowsClaimsAuthenticationHttpModule, Microsoft.SharePoint.IdentityModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /><add name="SPApplicationAuthentication" type="Microsoft.SharePoint.IdentityModel.SPApplicationAuthenticationModule, Microsoft.SharePoint.IdentityModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /><add name="Session" type="System.Web.SessionState.SessionStateModule" /></modules>

I would really appreciate your help with this since I can't find anything useful on the web.

Many thanks in advance and kind regards,

Thomas


Viewing all articles
Browse latest Browse all 7589

Trending Articles