How to set custom access denied pages in SharePoint 2013?

Hi everybody,
in SharePoint 2010 custom access denied or other error pages could be easily set by setting the new path to the webapp-properties by using webApp.UpdateMappedPage. In SharePoint 2013 this seems to be ignored. The MSDN-entry seems to be out of date and just
copied from SharePoint 2010:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebapplication.updatemappedpage.aspx
A possible workaround could be writing a HttpModule that checks the requested url for accessdenied.aspx and redirects to a custom page but there must be another more best practice way to achieve this behaviour??

I found a workaround to redirect to a custom access denied page but I'm not happy with it.
I created a HttpModule which uses static method SPCustomRedirect.RegisterRedirectHandler to register a class inheriting ISPCustomRedirectHandler to the current HttpContext. In this class there is a method GetRedirectUrl that returns the path to my custom
access denied page.
Now at last a value must be written to the HttpRequest.Querystring named "CustomRedirect". But to add something to the QueryString-NameValueCollection I must use reflection to make it writable because it's readonly. After setting the value, I reset the property
to readonly.
For clearness, I post the code-snippet from the HttpModule below:
HttpRequest request = HttpContext.Current.Request;
NameValueCollection QS = request.QueryString;
QS = (NameValueCollection)request.GetType().GetField("_queryString", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(request);
PropertyInfo readOnlyInfo = QS.GetType().GetProperty("IsReadOnly", BindingFlags.NonPublic | BindingFlags.Instance);
readOnlyInfo.SetValue(QS, false, null);
QS["CustomRedirect"] = "CustomAccessDenied";
readOnlyInfo.SetValue(QS, true, null);
SPCustomRedirect.RegisterRedirectHandler("CustomAccessDenied", new CustomAccessDenied());
This is the redirectHandler-class I register in the last line:
public class CustomAccessDenied : ISPCustomRedirectHandler
public string GetRedirectUrl(string key)
string serverRelativeUrl = string.Empty;
var ctx = HttpContext.Current.Items["DefaultSPContext"];
if (ctx != null)
serverRelativeUrl = ((SPContext)ctx).Web.ServerRelativeUrl;
if (serverRelativeUrl.Equals("/"))
serverRelativeUrl = string.Empty;
return string.Format("{0}/_layouts/15/myCode/CustomAccessDenied.aspx", serverRelativeUrl);
This works fine but I really don't like the need to add a value to the querystring by reflection or the need to do this for every page-request...
What's your opinion for this?

Similar Messages

  • How to delete i.e. clear the pending access requests list from Access request page in SharePoint 2013

    Hi Team,
    I am site collection admin of a SP13 site. The issue is we have added some of the users manually after we got requests from them for site access. But this has left those users as pending on Access requests page. We don't want that list to stack up.
    I can not decline those requests as those users will be notified with declined mail. I searched for clearing the list of those pending requests but did't find any guidelines for this. 
    Is there any way I can do this. Any help is appreciated thanks in advance  

    You might consider using PowerShell to remove unwanted items from the "Access Requests" list of the web site.  This list holds all of the access requests including pending, declined and approved.  The following example demonstrates removing
    the first item from the list.  Please note, I'm not aware whether or not there are any negative side effects to removing items from this list so doing so would be at your own risk.
    $web = get-spweb https://yoursharepointsite
    $list = $web.lists["Access Requests"]
    $list.items[0].delete()

  • How to set custom master page for social/sites.aspx in sharepoint 2013

    How to set custom master page for social/sites.aspx in sharepoint 2013.?
    File path is
    C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\FEATURES\SocialDataStore\SocialDataStoreList\sites.aspx
    Thanks in advance

    Hi,
    You could open the sites.aspx in Notepad or SharePoint designer, and set the master page to your own master page directly via editing:
    <%@ Page language="C#" MasterPageFile="~masterurl/custom.master"      Inherits="Microsoft.SharePoint.Portal.WebControls.FollowedContentWebPartPage,Microsoft.SharePoint.Portal,Version=15.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c"
    %>
    Regards,
    Rebecca Tu
    TechNet Community Support

  • How to set custom font family in qml label in black berry 10 os

    how to set custom font family in label text  qml in black berry 10 OS

    AFAIK, this is not the correct way to set the image location.
    We call the working directory as context, so inside the context root along with WEB-INF, maintain a folder with name img and put all the images in that directory.
    You can use either .\<image_folder> or the optimum way would be (if you are using JSPs) to use getContext() method and traverse accordingly.
    FYI,,, using getContext() will give you context root directory, from there it is as simple as accessing any other folder.
    Hope this answers your question.
    Cheers,
    Jeets.

  • How to fix custom access so permissions will work

    How to disable “custom” access setting on my hard drive which causes permissions problem?
    This is on a 2007 MBP with most recent OSX, etc.
    Here’s what I have tried based on posts I read on this forum:
    (1) I logged into admin account and typed into Terminal the following:
    sudo fsaclctl -p /Volumes/drivename -d
    sudo chmod -R +rwX /Volumes/drivename
    No go. Terminal does not recognize command fsaclctl
    (2) I also tried into terminal
    
sudo chflags nouch /Volumes/”drive-name”
    chmod 755 /Volumes/”drive-name”
    (3) I restarted with recovery disk and did repair permissions. No go.
    I saw a suggestion to erase the hard disk and reinstall OSX. I will do so (but would rather not) if it will solve the problem. Any advice is welcome.

    Try Settings > General > Reset > Reset Network Settings
    If that didn't helped:
    Do a reset (Hold Sleep/Wake and Home buttons about 10 secs or more till Apple logo appears)
    Note: You will not lose any data.

  • CR 2008 SDK: how to set custom paper size?

    Dear forum users, I'm trying to use Crystal Reports 2008 SDK to print barcode labels to a Datamax Printer.
    The printer uses a custom page size. Can anyone tell me how to set custom page size and margins using C# and CR2008 SDK?
    Best regards
    Alessandro

    I'm experiencing this problem: I need to print barcode labels which are 4 x 9 cm each (a custom paper size). The report has been build correctly, orientation is right but when I print the labels programmatically by an application I made the label gets printed in a wrong way.
    In particular, orientation and paper size are not correct.
    So I would like to try to force both of them (both the orientation and the custom paper size). How can I do that?
    Best regards
    Alessandro

  • How to set custom size of Close Button e.g. 32x32  of Title Window in Flex 4

    How to set custom size of Close Button e.g. 32x32 of Title Window in Flex 4?

    Hi
    Here is the code of the Button in the skin class of spark title window.
    <s:Button id="closeButton" skinClass="spark.skins.spark.TitleWindowCloseButtonSkin"
                              width="15" height="15" right="7" top="7" />
    So first change the default height and width from 15 to 32. Then in the Button Skin class i.e. spark.skins.spark.TitleWindowCloseButtonSkin change paths to modify the cross symbol.
    Hope this helps
    Rush-me

  • How to set Custom HTTP headers in HTTP binding?

    How to set custom HTTP headers before sending the Rest based request in HTTP binding?

    sharon38_74 wrote:
    they said that our internal application needs to send a "login request" to etran via SSL with the user's information encoded in base 64 format. etran captures the HTTP header containing user authentication and authorization information, and parses the required information from the HTTP header.
    My question is that how I set user information in HTTP header? From my understanding, once I am able to set the user information in HTTP header, it is in base 64 format?Your application need to act like a proxy. You can invoke a HTTP request programmatically using java.net.URLConnection. You can set request headers using URLConnection#setRequestProperty(). Also see the API docs: [http://java.sun.com/javase/6/docs/api/java/net/URLConnection.html]. You only need to know the header field name where to set the Base64-encoded value in. You need to Base64-encode the value yourself.

  • How to set title of jsp page from resource bundle

    hi ,
    How to set title of jsp page from resource bundle....

    Depends on how you configured and declared the resourcebundle in your JSP. The usual way is just<title>${resourceBundle.messageKey}</title>

  • Does anyone know how to customize a Site page on SharePoint 2013? Also does anyone have any recommendations on course to take to learn this?

    Hello All,
    I am new to using the 2013 SharePoint and want to customize the site pages that was set up by someone else. The problem is when i click on the site pages I only see the option to upload and new. So the pages that have been uploaded in the past i clicked
    on them and when they come up it just shows the title of the site page with edit links button on the top.  
    So basically you are not able to do anything. Does anyone know if this is a permissions issue and if it is how do i give myself admin rights
    Nexusxox

    Hi,
    From your description, you want to know how to edit a page in SharePoint 2013.
    Go to the page->click Settings->Edit page,refer to the following screenshot:
    If a user want to edit a page, he at least have edit permissions.
    If you have any problems, please don't hesitate to let me know.
    Best Regards,
    Lisa Chen
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Not able to Enable the Custom Ribbon button On Pages in Sharepoint 2013

    Hi Team,
    Not able to Enable the Custom Ribbon button On Pages in SharePoint 2013. we have used the button edit properties section of the Pages.
    Same is working for Lists but not for Pages.
    Thanks,
    Shrikant

    Thanks for your reply.
    Right now my server is not working to get the code. will share you in some time.
    I am just thinking if page get checked out and my control is also present in the Edit properties section then do I need to specify something explicitly to enable the button. The same is working for Lists.

  • How do I add multiple audio webparts to a page in SharePoint 2013?

    I need to add multiple media player webparts with audio files to a page in SharePoint 2013 so users can click the play button, listen to the file, then vote for the audio they like best. The problem is I can only get one audio to play at a time, and only
    in certain browsers. I can get them to work intermittently in a Chrome browser, but not IE 10. When I publish the page and click the play arrow, it played the first time. Then I added two more audio player webparts to the page, and linked them to different
    audio files (m4a and mpg). Now only one audio player will work, not the other 2.

    Hi
    Have you used this codeplex webpart
    https://mpwp.codeplex.com/
    Amit Kotha

  • How to hide username in comments section of sharepoint 2013 blog page

    I have a blog page in SharePoint 2013. In that, in the comments section, i have to hide the username of the person who posted the comment.
    I also have to hide it from the page source, hence i cannot use css. Please suggest some solution,if possible using xslt.

    Open the blog.xsl file which is located in "/_layouts/XSL/blog.xsl"
    For safe side take the back up of blog.xsl file and open it and find the below div
    <div class="ms-PostFooter">
    <!-- For the author field, render it using the span style and preceed it with the word "by"-->
    <span class="ms-postfootercolor"><xsl:value-of select="$thisNode/../@resource.wss.ByPrefix"/></span><xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text><xsl:call-template name="RenderAuthor"/>
    <xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text><span class="ms-postfootercolor"><xsl:value-of select="$thisNode/../@resource.wss.blog_postfooter_at"/><xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>
    <xsl:choose>
    <xsl:when test="$ContainerId"><xsl:text disable-output-escaping="yes">&lt;#= spMgr.RenderFieldByName("PublishedDate", listItem, listSchema) #&gt;</xsl:text></xsl:when>
    <xsl:otherwise><xsl:value-of select="@PublishedDate" disable-output-escaping="yes"/></xsl:otherwise>
    </xsl:choose></span>
    <div>
    In the above div remove the span tag
    <!-- For the author field, render it using the span style and preceed it with the word "by"-->
    <span class="ms-postfootercolor"><xsl:value-of select="$thisNode/../@resource.wss.ByPrefix"/></span><xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text><xsl:call-template name="RenderAuthor"/>
    If you any help please let me know

  • How to configure Search for a site in sharepoint 2013?

    Hi,
    I had a document library.
    1)I want to configure search so that I can search documents from previous month, quarterly, half year, year, and all documents is possible.
    2)Search results are organized with most recent documents at the top.
    3)Search results have year as refiner that can be used to show results only from specified year (In library we have field with year when document create)
    To achieve this what I have chane in site settings->search
    and what I have to write for Result Types, Query Rules
    Thanks

    Hi,
    Following are the steps you need to perform for creating the search center.
    http://blogs.technet.com/b/tothesharepoint/archive/2013/10/30/set-up-a-search-center-in-sharepoint-2013.aspx (About Search)
    1. Create the site collection by navigating to the CA(Central Admin) & select the Enterprise Search Center Template.
    2. Create Content Source -> Navigate to the Search Service application->Create the content source if the content comes from other content farm (if different farm accout  if it same add the site Collection URL in default Content Source. ( make
    sure the crawl account must have full read permission)
    http://blogs.technet.com/b/tothesharepoint/archive/2013/10/31/how-to-create-a-search-center-site-collection-and-enable-crawling-of-your-content-in-sharepoint-2013.aspx (Create
    Search Center)
    3. Once you add url in the content source and run the full crawl.
    4. Navigate to the Search center created at step 1 and try to search with the document name. you will see the document.
    http://blogs.technet.com/b/tothesharepoint/archive/2013/11/06/how-to-configure-the-search-results-web-part-to-use-a-new-result-source-in-sharepoint-2013.aspx (Go
    to the document Library and configure the result source)
    5. To configure the refiner please follow this post. You will see the modified refiner to refine your search http://blogs.technet.com/b/tothesharepoint/archive/2013/11/07/plan-to-use-refiners-on-a-search-results-page-in-sharepoint-2013.aspx)
    Let me know if you req. any other information.
    Regards,
    Basant Pandey
    http://sharepointfordeveloper.blogspot.com

  • Why are the web pages of SharePoint 2013 so devoid of colour and distinct boundaries and leave screen space unutilized

    Hi All,
    This was a comment from my business users who have worked with various versions of SharePoint. I understand SP 2013 has put in logic to make the web pages to be compatible with a wider set of browsers and screen form factors. Nevertheless, the issues raised
    by my business users are valid.
    Comparing a basic web part page of SP 2013 with SP 2007 and 2010, their feedback was:
    SP 2013 pages do not have clear boundaries
    SP 2013 pages are generally devoid of colour. This is makes it harder to visually distinguish links from ordinary text.
    SP 2013 pages appear to leave large swathes of screen space underutilized.
    Thanks,
    Saurabh
    Web part page on SP 2007
    Web part page on SP 2013
    sdg

    Hi,             
    1. When insert a web part in SharePoint 2013, you can edit the web part and change the appearance and layout of the web part.                                                                           
    You can add the boundaries for the web part. (Edit page->select a web part ->edit the web part->in the appearance section->in Chrome Type, select title and border->after that you can see the boundaries).
    2. The color of the links depends on the theme you have selected in SharePoint 2013. Different themes set the different colors of the links. You also can customize the theme or composed look in SharePoint 2013.
    The article below is about how to create a SharePoint composed look.
    https://bniaulin.wordpress.com/2012/12/16/step-by-step-create-a-sharepoint-2013-composed-look/
    3. In SharePoint 2013, the space between different zones is set by default.
     The picture below is my page in SharePoint 2013.
    If there is much space between zones, to check:
    1. If input much space in web part in the SharePoint 2013.
    2. If input space in the web pert zone in SharePoint 2013.
    3. If the width has been changed in the below code in the page which you change the text layout.
    <table id="layoutsTable" style="width: 100%">
        <tbody>
            <tr style="vertical-align: top">
    <td style="width: 100%">
    <div style="width: 100%">
    <div>
    </div>
    </div>
    </td>
            </tr>
        </tbody>
    </table>                                                                                     
    The article below is about when you edit the page and choose one style of the text layout, some code will be added in page automatically.
    https://social.technet.microsoft.com/Forums/office/en-US/0422f5e0-4374-4bf5-b4d8-c4f8f970c865/sharepoint-wiki-page-text-layout-column-width?forum=sharepointcustomizationprevious
    If you want to Remove/Hide empty space between web parts, you can add css code in the content edit web part.
    The article below is about this issue.
    http://havivi.blogspot.in/2009/08/removehide-empty-space-between-web.html
    Best regards
    Sara Fan
    TechNet Community Support

Maybe you are looking for