This is a migrated thread and some comments may be shown as answers.

[Solved] IsPostedFromThisSite attribute removing menu node

2 Answers 21 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michael
Top achievements
Rank 1
Michael asked on 04 Dec 2011, 02:22 PM
Hi

I am ussing the Menu control.

I have an attribute called [IsPostedFromThisSite]
[HttpGet]
public ActionResult Index()
{
	return View();
}
 
[HttpPost]
[ValidateAntiForgeryToken]
[IsPostedFromThisSite]
public ActionResult Index(LogOnModel model)
{
}
Here is my attribute code
	public class IsPostedFromThisSiteAttribute : AuthorizeAttribute
	{
		public override void OnAuthorization(AuthorizationContext filterContext)
		{
			if (filterContext.HttpContext != null)
			{
				if (filterContext.HttpContext.Request.UrlReferrer == null)
					throw new System.Web.HttpException("Invalid submission");
 
				if (filterContext.HttpContext.Request.UrlReferrer.Host != GlobalSettings.SiteHost)
					throw new System.Web.HttpException("This form wasn't submitted from this site!");
			}
			base.OnAuthorization(filterContext);
		}
	}

This attribute makes the Telerik menu not show the Index action at all. Any ideas how this can be fixed?




2 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 05 Dec 2011, 06:07 PM
Hello Michael,

 
I believe the issue is related with the added support for global authorization attributes. Check this forum thread for more information. If you have any issues, I will ask you to send us a simple test project in order to review it locally and advice you further.

Regards,
Georgi Krustev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Michael
Top achievements
Rank 1
answered on 08 Dec 2011, 12:12 PM
Thank you! That worked. Here is my complete extension now if anyone else runs into this problem.

public class IsPostedFromThisSiteAttribute : AuthorizeAttribute
{
	public override void OnAuthorization(AuthorizationContext filterContext)
	{
		if (filterContext.HttpContext != null)
		{
			if (filterContext.HttpContext.Request.UrlReferrer == null)
				throw new System.Web.HttpException("Invalid submission");
 
			if (filterContext.HttpContext.Request.UrlReferrer.Host != GlobalSettings.SiteHost)
				throw new System.Web.HttpException("This form wasn't submitted from this site!");
		}
		base.OnAuthorization(filterContext);
	}
 
	protected override bool AuthorizeCore(HttpContextBase httpContext)
	{
		return true;
	}
}
Tags
Menu
Asked by
Michael
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Michael
Top achievements
Rank 1
Share this question
or