Try our conversational search powered by Generative AI!

Custom Access denied page for EPiserver media files

Vote:
 

Hello,

I am new to Episerver and trying to figure out below mentioned issue.

I have implemented a 404 page based httperrors from web.config. I have implemented a custom access denied page so that users see this page instead of redirecting to start page. The reference used is from 

https://world.episerver.com/forum/developer-forum/-Episerver-75-CMS/Thread-Container/2014/8/Display-Insufficient-Permission-Messaging-instead-of-redirecting-to-login/

This access denied logic works for page types but when I have a media file (pdf etc) on click of it, this still takes me to start page instead of access denied page.

Any inputs on how can I redirect to my access denied page instead of start page when navigating to a media file and user doesnt have appropriate access.

Thanks.

 

#207555
Sep 24, 2019 17:39
Vote:
 

try implement and register in your IoC `EPiServer.Web.IAccessDeniedHandler`. It has `void AccessDenied(HttpContextBase context);` method that you can implement to handle access denied scenario for media content.

keep in mind that this service can be used in other scanrios as well, so you might need to fine tune checking HttpContext and fork handling logic.

#207563
Sep 25, 2019 6:02
Dileep D - Sep 26, 2019 20:52
Can this be used for both pages and media files since I have pages working and only issue with Media files (Ex: pdf). Also if possible do you have a sample code regarding implementing AccessDenied method.
valdis - Sep 26, 2019 20:59
I was just actually reading `EPiServer.Web.BlobHttpHandler` source code. It uses `IAccessDeniedHandler` under the hood. You can check private method called `ProccessBlobRequest()`.
valdis - Sep 26, 2019 20:59
sorry don't have sample implementation at hand.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.