[{"data":1,"prerenderedAt":98},["ShallowReactive",2],{"/2025/12/11-checking-anonymous-authentication-allowed-on-asp.net-owin-middleware-and-web-forms":3},{"id":4,"title":5,"body":6,"date":89,"description":72,"extension":90,"meta":91,"navigation":92,"path":93,"robots":94,"seo":95,"stem":96,"__hash__":97},"posts/2025/12/11 checking-Anonymous-Authentication-Allowed-on-ASP.NET-OWIN-middleware-and-Web-Forms.md","11 Checking Anonymous Authentication Allowed On ASPNET OWIN Middleware And Web Forms",{"type":7,"value":8,"toc":86},"minimark",[9,18,25,28,31,33,36,38,41,54,56,59,73,75,78],[10,11,13],"post-title",{":date":12},"date",[14,15,17],"h1",{"id":16},"checking-anonymous-authentication-allowed-on-aspnet-owin-middleware-and-web-forms","Checking Anonymous Authentication Allowed on ASP.NET OWIN Middleware and Web Forms",[19,20,21],"notes",{},[22,23,24],"p",{},"This is a repost from my old blog. First posted in 7/13/2020.",[26,27],"br",{},[22,29,30],{},"Some business logic on our web application apparently caused issue when hitting a page that allow anonymous authentication. And it seems there is no simple flag that indicates whether a page requires authorization or not.",[26,32],{},[22,34,35],{},"I need to check for allow anonymous in ASP.NET Web Forms page and on OWIN middleware.",[26,37],{},[22,39,40],{},"For ASP.NET Web Forms page, I found the following thread in StackOverflow which works great:",[22,42,43],{},[44,45,48],"span",{"className":46},[47],"text-blue-600",[49,50,51],"a",{"href":51,"rel":52},"https://stackoverflow.com/questions/8662922/programmatically-check-if-page-requires-authentication-based-on-web-config-setti",[53],"nofollow",[26,55],{},[22,57,58],{},"In my case, I need to convert the code to VB.NET, so it becomes:",[60,61,62],"code-block",{},[63,64,69],"pre",{"className":65,"code":67,"language":68},[66],"language-text","Dim principal = New GenericPrincipal(New GenericIdentity(String.Empty, String.Empty), New String() {})\nDim isAllowAnonymous = UrlAuthorizationModule.CheckUrlAccessForPrincipal(Page.AppRelativeVirtualPath, principal, Context.Request.HttpMethod).ToString()\n","text",[70,71,67],"code",{"__ignoreMap":72},"",[26,74],{},[22,76,77],{},"And on OWIN middleware, I need to tweak the above a little bit, so it becomes:",[60,79,80],{},[63,81,84],{"className":82,"code":83,"language":68},[66],"Dim principal = New GenericPrincipal(New GenericIdentity(String.Empty, String.Empty), New String() {})\nDim isAllowAnonymous = UrlAuthorizationModule.CheckUrlAccessForPrincipal(context.Request.Uri.AbsolutePath, principal, context.Request.Method)\n",[70,85,83],{"__ignoreMap":72},{"title":72,"searchDepth":87,"depth":87,"links":88},2,[],"2025-12-11T00:00:00.000Z","md",{},true,"/2025/12/11-checking-anonymous-authentication-allowed-on-asp.net-owin-middleware-and-web-forms",null,{"title":5,"description":72},"2025/12/11 checking-Anonymous-Authentication-Allowed-on-ASP.NET-OWIN-middleware-and-Web-Forms","bbFKp-NZ6ck4-vuP4HZ_j9t2Ik4VVAnsZsEcIDw0Enw",1785167452207]