Developer forum

Forum » Templates » Password protected page

Password protected page

Anders Ebdrup
Reply

Hi all,

 

How do I check with the template tags if a page is password protected (not user protected) as I need to hide a column in the master template if a page is password protected and the user do not have access to the password protected area?

 

Best regards, Anders

 


Replies

 
Mikkel Ricky
Reply
This post has been marked as an answer

There's no built-in template tag for checking if a page is password protected.

You have at least three options to work around this

  1. Use a condition to check if some unique string that (with very high probability) only occurs in your login form occurs in the page content (see below)
  2. Create a page template extender (check Page.Protect and Page.Password)
  3. Use Razor in your layout template to check if the page is password protected 

I recommend going for number 3. 

For number 1 you can add

<!--SomeStringThatOnlyOccursInTheLoginForm-->

to your login template and then check for this in your master template

<!--@If(DwContent(content)<contains>SomeStringThatOnlyOccursInTheLoginForm)-->
<pre>This page is protected by a password</pre>
<!--@EndIf-->

(replace "content" with the id of the first content placeholder in your layout). It's a hack, but it works.

Best regards,
Mikkel

Votes for this answer: 1
 
Anders Ebdrup
Reply

Hi Mikkel,

 

Thanks for the answer! Then I will go with number 2 for this solution :-)

But at the same time I would like to make a feature request for having access to this tag directly in the page related tags :-)

 

Best regards, Anders

 
Anders Ebdrup
Reply

Hi  Mikkel,

 

Next issue; After entering the password how can I see that the user now have access to the area?

 

Best regards, Anders

 
Mikkel Ricky
Reply
This post has been marked as an answer

You have to check that the session variable with the page password as key has a value that's equal to the page password (!). It's easier to explain with a piece of code:

var page = ...;
var hasAccess = (string)System.Web.HttpContext.Current.Session[page.Password] == page.Password;

 

Best regards,
Mikkel

 

Votes for this answer: 1
 
Anders Ebdrup
Reply

Thanks, Mikkel. It works ! :-)
 

 

You must be logged in to post in the forum