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

[Solved] HttpUnhandledException thrown when more than one Authorisation filter assigned to a controller

1 Answer 108 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.
Nick
Top achievements
Rank 1
Nick asked on 16 Nov 2009, 03:11 PM
We have custom authentication filters that we use to extend the abilities of the default <Authorize> filter.  Having added the new MVC menu to the project, an error is thrown when a menu item is added that references a controller with multiple authorisation filters.

Menu:
  <div id="navigation"
    <
      Dim mainMenu As Telerik.Web.Mvc.UI.Menu = Html.Telerik.Menu.Name("mainMenu") 
       
      Dim miHome = New Telerik.Web.Mvc.UI.MenuItem With {.Text = "Home".ControllerName = "Home".ActionName = "Index"
      mainMenu.Items.Add(miHome) 
       
      Dim miNews = New Telerik.Web.Mvc.UI.MenuItem With {.Text = "News".ControllerName = "News".ActionName = "Index"
      mainMenu.Items.Add(miNews) 
       
      Dim miDocuments = New Telerik.Web.Mvc.UI.MenuItem With {.Text = "Documents".ControllerName = "Documents".ActionName = "Index"
      mainMenu.Items.Add(miDocuments) 
       
      Dim miReports = New Telerik.Web.Mvc.UI.MenuItem With {.Text = "Reports".ControllerName = "Reports".ActionName = "Index"
      mainMenu.Items.Add(miReports) 
       
      Dim miCalls = New Telerik.Web.Mvc.UI.MenuItem With {.Text = "Calls".ControllerName = "Calls".ActionName = "Index"
      Dim miNewCall = New Telerik.Web.Mvc.UI.MenuItem With {.Text = "Log a Call".ControllerName = "Calls".ActionName = "Create"
      Dim miNewRfc = New Telerik.Web.Mvc.UI.MenuItem With {.Text = "Log a Change Request".ControllerName = "Calls".ActionName = "CreateChangeRequest"
      miCalls.Items.Add(miNewCall) 
      miCalls.Items.Add(miNewRfc) 
      mainMenu.Items.Add(miCalls) 
 
      mainMenu.Render() 
    %> 
  </div> 
 

Controller:
<AuthorizeChangePassword(Order:=0)> _ 
<AuthorizeWithRedirect(Order:=2, Roles:="CallsReader", Controller:="Home", Action:="Unauthorised")> _ 
Public Class CallsController 
  Inherits System.Web.Mvc.Controller 
... 

Exception thrown:
System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.InvalidOperationException: Sequence contains more than one element 
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source) 
   at Telerik.Web.Mvc.Infrastructure.Implementation.AuthorizeAttributeCache.GetInternal(ICustomAttributeProvider controllerType, IEnumerable`1 actionMethods) 
   at Telerik.Web.Mvc.Infrastructure.Implementation.AuthorizeAttributeCache.<>c__DisplayClass1.<GetAuthorizeAttributes>b__0() 
   at Telerik.Web.Mvc.Infrastructure.CacheBase`2.GetOrCreate(TKey key, Func`1 factory) 
   at Telerik.Web.Mvc.Infrastructure.Implementation.AuthorizeAttributeCache.GetAuthorizeAttributes(RequestContext requestContext, String controllerName, String actionName) 
   at Telerik.Web.Mvc.Infrastructure.Implementation.ControllerAuthorization.IsAccessibleToUser(RequestContext requestContext, String controllerName, String actionName) 
   at Telerik.Web.Mvc.Infrastructure.Implementation.NavigationItemAuthorization.IsAccessibleToUser(RequestContext requestContext, INavigatable navigationItem) 
   at Telerik.Web.Mvc.UI.Menu.WriteItem(MenuItem item, IMenuRenderer renderer) 
   at Telerik.Web.Mvc.UI.Menu.<>c__DisplayClass7.<WriteHtml>b__6(MenuItem item) 
   at Telerik.Web.Mvc.Extensions.EnumerableExtensions.Each[T](IEnumerable`1 instance, Action`1 action) 
   at Telerik.Web.Mvc.UI.Menu.WriteHtml(HtmlTextWriter writer) 
   at Telerik.Web.Mvc.UI.ViewComponentBase.Render() 
   at ASP.views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in C:\Documents and Settings\nfoster\My Documents\Visual Studio Projects\Client Portal 3\Trunk\src\Stargate3.Web\Views\Shared\Site.Master:line 79 
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) 
   at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) 
   at System.Web.UI.Control.Render(HtmlTextWriter writer) 
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) 
   at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) 
   at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) 
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) 
   at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) 
   at System.Web.UI.Page.Render(HtmlTextWriter writer) 
   at System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) 
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) 
   at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) 
   at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) 
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
   --- End of inner exception stack trace --- 
   at System.Web.UI.Page.HandleError(Exception e) 
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
   at System.Web.UI.Page.ProcessRequest() 
   at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) 
   at System.Web.UI.Page.ProcessRequest(HttpContext context) 
   at ASP.views_home_index_aspx.ProcessRequest(HttpContext context) 
   at System.Web.Mvc.ViewPage.RenderView(ViewContext viewContext) 
   at System.Web.Mvc.WebFormView.RenderViewPage(ViewContext context, ViewPage page) 
   at System.Web.Mvc.WebFormView.Render(ViewContext viewContext, TextWriter writer) 
   at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) 
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) 
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<InvokeActionResultWithFilters>b__e() 
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) 
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10() 
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) 
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) 
   at System.Web.Mvc.Controller.ExecuteCore() 
   at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) 
   at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) 
   at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) 
   at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) 
   at System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) 
   at System.Web.Mvc.MvcHttpHandler.VerifyAndProcessRequest(IHttpHandler httpHandler, HttpContextBase httpContext) 
   at System.Web.Routing.UrlRoutingHandler.ProcessRequest(HttpContextBase httpContext) 
   at System.Web.Routing.UrlRoutingHandler.ProcessRequest(HttpContext httpContext) 
   at System.Web.Routing.UrlRoutingHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext context) 
   at Attenda.Stargate.Web._Default.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\nfoster\My Documents\Visual Studio Projects\Client Portal 3\Trunk\src\Stargate3.Web\Default.aspx.vb:line 12 
   at System.Web.UI.Control.OnLoad(EventArgs e) 
   at System.Web.UI.Control.LoadRecursive() 
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
   at System.Web.UI.Page.ProcessRequest() 
   at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) 
   at System.Web.UI.Page.ProcessRequest(HttpContext context) 
   at ASP.default_aspx.ProcessRequest(HttpContext context) 
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 
 

Strangely, it has no problem with one filter on the controller and one on the action, just if they are both on the controller.

For a short term fix I can try to merge the different filters into one but it may be useful information for you guys in the future,

Any work arounds or fixes would be gratefully received,
Nick




1 Answer, 1 is accepted

Sort by
0
Kazi Manzur Rashid
Telerik team
answered on 17 Nov 2009, 12:15 AM
Hello Nick,

It seems it is a bug at our end, we did not anticipated that there will be more than one Authorization. attribute. Anyway please replace the it with the attached file for the time being.  

Best wishes,
Kazi Manzur Rashid
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Menu
Asked by
Nick
Top achievements
Rank 1
Answers by
Kazi Manzur Rashid
Telerik team
Share this question
or