Giter Site home page Giter Site logo

joaf123 / asp.net-webforms-authentication Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 73 KB

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

License: GNU General Public License v3.0

C# 100.00%
asp-net-web-forms asp-net-webform custom-authorize-asp-net http-module authorization-asp-net-framework formsauthentication httpmodule auth authorization-middleware asp-auth

asp.net-webforms-authentication's Introduction

Verify FormsAuthentication cookie on request using a custom attribute

ASP.NET Core inspired request authentication, using a custom attribute & FormsAuthentication in legacy ASP.NET Website Projects! Supports WebMethods, Page Classes, MasterPage Classes & WebService Classes

Setup:

Prerequisite

IIS needs to be running in integrated mode. Classic mode is not supported due to the nature of the classic IIS pipeline

Web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <!--RequireAuthentication Module-->
        <modules>
            <add name="AttributeBasedFormsAuthenticationModule" type="AttributeBasedFormsAuthenticationModule" preCondition="integratedMode" />
        </modules>
    </system.webServer>
</configuration>

Global.asax:

VB syntax

<%@ Application Language="VB" %>

<script RunAt="server">
    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        Me.UseAuthentication()
    End Sub
</script>

C# syntax

<%@ Application Language="C#" %>

<script RunAt="server">
    void Application_Start(object sender, EventArgs e)
    {
        this.UseAuthentication();
    }
</script>

Supported Use:

WebService Classes:

[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

HttpHandler Classes:

[RequiresAuthentication]
public class dropzone_FileUpload : IHttpHandler, System.Web.SessionState.IRequiresSessionState

Page Classes:

[RequiresAuthentication]
public partial class WebFormsPage : System.Web.UI.Page

MasterPage Classes:

[RequiresAuthentication]
public partial class WebFormsMasterPage : System.Web.UI.MasterPage

WebMethods inside Page Classes & WebMethods inside WebService Classes:

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.