1

I have SharePoint web application. Need to redirect to custom login page after session timeout.

Where is the exact location in web.config file to do this redirection or any code behind file or login.aspx.cs file can I do it?

I think the defualt asp.net web.config can do it as below.

<authentication mode="Forms">
    <forms defaultUrl="~/Default.aspx"
        loginUrl="~/Login.aspx"
        slidingExpiration="true"
        timeout="60" />
</authentication>

I have found that there are many more session state timeouts in web.config. What exactly should I change to change the session timeout?

 <system.web>
 <sessionState mode="SQLServer" timeout="60" allowCustomSqlDatabase="true" sqlConnectionString="Data Source=91.1.1.1;Initial Catalog=SP_SessionState;Integrated Security=True;Enlist=False;Pooling=True;Min Pool Size=0;Max Pool Size=100;Connect Timeout=15" />
  </system.web>

and also I found another timeout.

 <pages enableSessionState="false" 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">

And also there are many aspx session timeouts in web.config.

<location path="_layouts/UploadEx.aspx">
    <system.web>
      <httpRuntime maxRequestLength="2097151" executionTimeout="3600" />
    </system.web>
  </location>
  <location path="_layouts/15/UploadEx.aspx">
    <system.web>
      <httpRuntime maxRequestLength="2097151" executionTimeout="3600" />
    </system.web>
  </location>
  <location path="_layouts/NewVideoSet.aspx">
    <system.web>
      <httpRuntime maxRequestLength="2097151" executionTimeout="3600" />
    </system.web>
  </location>

Currently I have a custom login page under _layouts/mysite/login.aspx directory. Currently if my session expired it goes to SharePoint default error page,then I need to clear the cache again to go for the login page.

Might be the reason of which I have used HttpContext.Current.Session["CustomSessionName"] variables in login page as well as in other pages. Do I need to remove the session varibales used in code?

Any idea how to avoid from this and need to redirect to login page when user refresh the page after the http session timeout.

0

Try below code.

 <authentication mode="Forms">
  <forms loginUrl="/_layouts/15/mysite/login.aspx" />
</authentication>

Let me it's work for you.

Thanks

  • I already have this in web.config. But I have a quastion on having a session variable in page load? Is that caused to happen error when http sessions are timeout? – KIS Feb 9 '17 at 8:01
  • Yes it's caused – Bharat Khunti Feb 9 '17 at 10:20
  • You need to handle exception – Bharat Khunti Feb 9 '17 at 10:29
0

You need Check if session has expired or not created

You can by if condition. like,

  if(session["sessionName"]!=null || session["sessionName"]!="")
  {
     //code here
  }
  else
  {
       Response.Redirect("login.aspx")
  }

Or you can used try {} catch() block to handle null exception. Because if session was expired you will get null value.

  • How can I handle exception if I need to check in every page? Are there any one place or a class to check this like web.config do normally? Otherwise do I I need to add try catch in every page? – KIS Feb 23 '17 at 7:56
  • You can create one common method and call it from every page. – Bharat Khunti Feb 23 '17 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.