API
Version 7.x > API > Redirect to Home Page if requested page is not published View modes: 
User avatar
Member
Member
anshuman.shandilya-aonhewitt - 11/11/2013 7:10:32 AM
   
Redirect to Home Page if requested page is not published
Hi,

I have changed "Published To" property of document to one day prior to current date to make it non-published. Now I want, if user try to open this non-pulished page by entering a url in browser, system should open homepage of my site.

Please suggest where (which event) can I check current document's published status and how ?

Thanks
Anshuman

User avatar
Kentico Support
Kentico Support
kentico_janh - 11/11/2013 7:58:07 AM
   
RE:Redirect to Home Page if requested page is not published
Hello,

You can simply set the Site Manager -> Settings -> Content -> Page not found URL to point to your Home page.

Best regards,
Jan Hermann

User avatar
Member
Member
anshuman.shandilya-aonhewitt - 11/11/2013 10:22:19 AM
   
RE:Redirect to Home Page if requested page is not published
Hi Jan,

Thanks for the solution. I changed that setting and I see home page. But somehow HttpContext.Current.Session becomes null in this case. One on the control on Home Page is using data stored in session which is not rendering right in this case.
Do you know if HttpContext.Current.Session becomes null if page is not found in Kentico?

Thanks
Anshuman

User avatar
Kentico Support
Kentico Support
kentico_janh - 11/18/2013 2:31:28 AM
   
RE:Redirect to Home Page if requested page is not published
Hello,

You are right. The 404 handling must be done by server transfer and in this case the session is not transferred. The easiest solution is make one extra redirection, so please create other 404 page and place for instance the Random redirection web part on the default 404 page with one target url (the new 404 page). Or you can redirect to the same page, but you need to handle the endless loop.

Best regards,
Jan Hermann