Skip to content

ASP.NET Core inspired request authentication, using a custom attribute & FormsAuthentication in legacy ASP.NET Website Projects

License

Notifications You must be signed in to change notification settings

joaf123/ASP.NET-WebForms-Authentication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Verify FormsAuthentication cookie on request through custom attribute

httpModule for verification of FormsAuthentication cookie on request, using a custom attribute.

Currently supported use cases:

C#:

Decorated on a PageMethod or ASP.NET Ajax WebMethod:

[RequiresAuthentication]
[WebMethod]
public string AjaxMethod() {

Decorated on a Page, MasterPage or ASP.NET Ajax WebService Class:

Page Class:
[RequiresAuthentication]
public partial class WebFormsPage : System.Web.UI.Page
MasterPage Class:
[RequiresAuthentication]
public partial class WebFormsMasterPage : System.Web.UI.MasterPage
WebService Class:
[RequiresAuthentication]
[System.Web.Script.Services.ScriptService()]
[WebService(Namespace = "http://localhost:8080/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[global::Microsoft.VisualBasic.CompilerServices.DesignerGenerated()]
public class AspAjaxWebService : System.Web.Services.WebService
{
}

VB:

Decorated on a PageMethod or ASP.NET Ajax WebMethod:

<RequiresAuthentication>
<WebMethod>
public function AjaxMethod() as string 

Decorated on a Page, MasterPage or ASP.NET Ajax WebService Class

Page Class:
<RequiresAuthentication>
Partial Class WebFormsPage
    Inherits System.Web.UI.Page
MasterPage Class:
<RequiresAuthentication>
Partial Class WebFormsMasterPage
    Inherits System.Web.UI.MasterPage
WebService Class:
<RequiresAuthentication>
<System.Web.Script.Services.ScriptService()>
<WebService([Namespace]:="http://localhost:8080/")>
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)>
<[global].Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Public Class AspAjaxWebService
    Inherits System.Web.Services.WebService
End Class

Remember to set the FormsAuthentication cookie!