Is it possible to create a Partial View that has a controller that can be called from another view using
Html.RenderAction (...)
BUT without the same controller being accessible via URL?
So for example
public class ArticlesController : Controller { public ActionResult HomeList() ... }
Lists recent articles for the bottom of my web pages.
Therefore i call it from
_Layout.cshtml
However, I do not want anyone to come to
mysite.com/Articles/HomeList
and seeing the same list for various reasons (security, SEO, etc.)
thanks
Edit:
As a result, I used my own attribute class, thanks to the help of Rus:
public class ChildActionOnly404Attribute : FilterAttribute, IAuthorizationFilter { void IAuthorizationFilter.OnAuthorization(AuthorizationContext filterContext) { if (!filterContext.IsChildAction) { throw new HttpException(404, ""); } } }
source share