0

I currently am working on SharePoint 2016, where I would like people from only specific group to view viewlsts.aspx page otherwise the people should be redirected to another page.

As I cannot inject script on viewlsts.aspx page, is there any other option on how can we manage on this.

I also don't to deploy any solution(wsp) for the same, need to achieve using out of the box or without wsp deployment.

  • This is not possible using any OOTB solution. – Ganesh Sanap May 15 at 11:55
  • any custom script that I can place some where ? – Muskan May 15 at 11:58
  • Doing it with a script is just security through obscurity, can't you just set permissions on lists and libraries – Anders Aune May 15 at 14:13
0

Hiding the viewlsts.aspx or its contents from the user should not be the approach for limiting access to lists or libraries. You should rather set appropriate permissions on list/library level to make only those lists accessible to users that they are allowed to open.


If the above is no solution in your case, you can still hide the content or redirect the user using a script. As you already stated, it is impossible to place such script using a Script Editor WebPart as the page itself is an application page and not a content page and not editable.

But you can still register a script to be executed using so-called User Custom Actions. Those can be registered either for an individual site or a whole site collection, but not on greater scope (i.e. not for a whole web application or the whole farm). See the Microsoft Docs on how to register such a User Custom Action.

In the Script Source attribute of the User Custom Action, you can then link to a JS file that you upload to a libary in SharePoint that every user can access (e.g. Style Library). The script then if effectively executed for every user and has to check for itself whether the user is on viewlsts.aspx by evaluating the URL, whether the user can access the page by evaluating e.g. group membership and then hide the content or redirect to another page.

0

Only way is to inject the script via masterpage, you can create a json reference object to match against a particular page then redirect. Sample code here: https://gist.github.com/jonathanhotono/edbdbe11aeaad409ae04c33da88f5028

  • I would strongly discourage from editing/customizing the master page as it may impede future upgrades of the site. Rather use User Custom Actions, which of course can also be combined with a mechanism like in your sample code. – Anon May 15 at 12:57
0

If you are using Classic mode, a User Custom Action is the best way to inject code into any specific page.

I would recommend making a JS file that you can selectively target a page with something like:

if(window.location.pathname.indexOf('viewlsts.aspx') > -1){
  <code here>
}

I highly recommend using this library ($SP.ca) to register a custom action. see the Usage section commented on the bottom for the ability to copy and paste a template for what you're trying to do.

I created a plugin for the SP.js api that handles redirects if a site is in classic mode. Feel free to use/tinker with it: SP.Redirect

Copy and paste it into the console, then run any of the usage scripts in the comment to see how it looks. When testing, I recommend setting override to 'true' so you can click on the timer and stop the redirect from happening.

There are some other steps necessary to make it not trigger for certain groups. Please see vgrem's solution for this, SP.IsCurrentUserMemberOfGroup.js

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.