Skip to Content
Professional ASP.NET 3.5 Security, Membership, and Role Management with C# and VB
book

Professional ASP.NET 3.5 Security, Membership, and Role Management with C# and VB

by Bilal Haidar, Stefan Schackow
November 2008
Intermediate to advanced
935 pages
30h 36m
English
Wrox
Content preview from Professional ASP.NET 3.5 Security, Membership, and Role Management with C# and VB

15.6. Supporting Dynamic Applications

The RoleProvider base class defines the abstract property ApplicationName. As a result, you can use the same approach for supporting multiple applications on-the-fly with SqlRoleProvider as was shown earlier for SqlMembershipProvider. After you have a way to set the application name dynamically on a per-request basis, you can write a custom version of SqlRoleProvider that reads the application name from a special location. Remember that in Chapter 12 an HttpModule was used that looked on the querystring for a variable called appname. Depending on the existence of that variable as well as its value, the module would store the appropriate application name in HttpContext.Items["ApplicationName"]. You can use the same module with a custom version of the SqlRoleProvider.

C#

using System;
using System.Web;
using System.Web.Security;

public class CustomRoleProvider : SqlRoleProvider
{
    public override string ApplicationName
    {
        get
        {
            string appNameFromContext =
                (string)HttpContext.Current.Items["ApplicationName"];
            if (appNameFromContext != "NOTSET")
                return appNameFromContext;
            else
                return base.ApplicationName;
        }
    }
}

VB.NET

Imports Microsoft.VisualBasic Imports System Imports System.Web Imports System.Web.Security Public Class CustomRoleProvider Inherits SqlRoleProvider Public Overrides Property ApplicationName() As String Get Dim appNameFromContext As String = _ CStr(HttpContext.Current.Items("ApplicationName")) If appNameFromContext <> "NOTSET" Then ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Professional ASP.NET 3.5 SP1 Edition: In C# and VB

Professional ASP.NET 3.5 SP1 Edition: In C# and VB

Bill Evjen, Scott Hanselman, Devin Rader
Professional C# 5.0 and .NET 4.5.1

Professional C# 5.0 and .NET 4.5.1

Christian Nagel, Jay Glynn, Morgan Skinner
Visual Basic 2015 Unleashed

Visual Basic 2015 Unleashed

Alessandro Del Sole

Publisher Resources

ISBN: 9780470379301Purchase book