Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7818287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:31:52+00:00 2026-06-02T06:31:52+00:00

Having trouble figuring out how to impersonate another user while using aspnet_personalization with Windows

  • 0

Having trouble figuring out how to impersonate another user while using aspnet_personalization with Windows authentication.

I am using asp.net’s personalization framework on my page:

        <asp:WebPartManager ID="WebPartManager1" runat="server" >
            <Personalization Enabled="True" />
        </asp:WebPartManager>

My page is in an existing web app that uses AuthenticationMode=”Windows” (which I cannot change, and IIS is also set to Windows Authentication). This web app has a page that allows super-users to impersonate any other user. This is accomplished by manipulating a connection string that is built dynamically every time we hit the database.

My problem is that aspnet_personalization still uses windows authentication. When I try to edit the connection string used by aspnet_personalization dynamically, aspnet does not seem to use it – it still uses the username of the current NT account.

I have the following in my web.config’s configuration tag:

  <connectionStrings>
    <remove name="LocalSqlServer"/>
    <add name="AnotherConnectionString" connectionString="Data Source=serverName;Initial Catalog=dbName;Integrated Security=True" providerName="System.Data.SqlClient"/>
  </connectionStrings>
<system.web>
  <membership>
    <providers>
      <remove name="AspNetSqlMembershipProvider"/>
      <add name="AspNetSqlMembershipProvider"  
         type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" 
         applicationName="/" 
         connectionStringName="AnotherConnectionString" />
    </providers>
  </membership>
  <profile enabled="true" defaultProvider="TableProfileProvider">
    <providers>
      <clear />
      <add name="TableProfileProvider" type="Microsoft.Samples.SqlTableProfileProvider" connectionStringName="AnotherConnectionString" table="aspnet_Profile" applicationName="/" />
    </providers>
  <!--<properties></properties>-->
  </profile>

I tried editing the connection string by adding code as follows whenever we impersonate a user, hoping asp.net would use it, but it does not:

    Dim settings = ConfigurationManager.ConnectionStrings("AnotherConnectionString")
    Dim fi = GetType(ConfigurationElement).GetField("_bReadOnly", BindingFlags.Instance Or BindingFlags.NonPublic)
    fi.SetValue(settings, False)
    settings.ConnectionString = "data source=serverName;database=dbName;user id=" & login & "; password=" & password

I did confirm on page_load of the page containing the webPartManager that “AnotherConnectionString” does contain the desired username, but asp.net_personalization still calls its stored procs using the NT username.

ANSWER:

Stackoverflow won’t let me post an answer. That’s ridiculous, so after I post the answer inside the question, I’m deleting my account and will encourage others to do the same.

I solved the problem by extending SqlPersonalizationProvider:

Imports System.Web.UI.WebControls.WebParts
Public Class MySqlPersonalizationProvider
   Inherits SqlPersonalizationProvider

    Protected Overrides Sub LoadPersonalizationBlobs(ByVal webPartManager As System.Web.UI.WebControls.WebParts.WebPartManager, ByVal path As String, ByVal userName As String, ByRef sharedDataBlob() As Byte, ByRef userDataBlob() As Byte)
        Dim impersonatedName As String = MySession.UserLoginName()
        path = path & "|" & impersonatedName
        userName = impersonatedName
        MyBase.LoadPersonalizationBlobs(webPartManager, path, userName, sharedDataBlob, userDataBlob)
    End Sub

    Protected Overrides Sub SavePersonalizationBlob(ByVal webPartManager As System.Web.UI.WebControls.WebParts.WebPartManager, ByVal path As String, ByVal userName As String, ByVal dataBlob() As Byte)
        Dim impersonatedName As String = MySession.UserLoginName()
        path = path & "|" & impersonatedName
        userName = impersonatedName
        MyBase.SavePersonalizationBlob(webPartManager, path, userName, dataBlob)
    End Sub
End Class

And then in web.config:

<system.web>
  <webParts>
    <personalization defaultProvider="AspNetSqlPersonalizationProvider">
      <providers>
        <remove name="AspNetSqlPersonalizationProvider"/>
        <add name="AspNetSqlPersonalizationProvider"
             type="MyProject.MySqlPersonalizationProvider"
             connectionStringName="MyConnectionString"
             applicationName="/"></add>
      </providers>
    </personalization>
  </webParts>

  <profile enabled="true" defaultProvider="TableProfileProvider">
    <providers>
      <clear />
      <add name="TableProfileProvider" type="Microsoft.Samples.SqlTableProfileProvider" connectionStringName="iCaseHomepage" table="aspnet_Profile" applicationName="/" />
    </providers>
  </profile>
</system.web>
<connectionStrings>
  <remove name="LocalSqlServer"/>
  <add name="MyConnectionString" connectionString="Data Source=MyServerName;Initial Catalog=MyDatabaseName;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>

and on the page:

        <asp:WebPartManager ID="WebPartManager1" runat="server" >
            <Personalization Enabled="True" />
        </asp:WebPartManager>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:31:56+00:00Added an answer on June 2, 2026 at 6:31 am

    Looks like I’m allowed to post an answer now. I guess I won’t delete my account after all. But geez, SO isn’t very friendly to noobs.

    Anyway, I solved the problem by extending SqlPersonalizationProvider:

    Imports System.Web.UI.WebControls.WebParts
    Public Class MySqlPersonalizationProvider
       Inherits SqlPersonalizationProvider
    
        Protected Overrides Sub LoadPersonalizationBlobs(ByVal webPartManager As System.Web.UI.WebControls.WebParts.WebPartManager, ByVal path As String, ByVal userName As String, ByRef sharedDataBlob() As Byte, ByRef userDataBlob() As Byte)
            Dim impersonatedName As String = MySession.UserLoginName()
            path = path & "|" & impersonatedName
            userName = impersonatedName
            MyBase.LoadPersonalizationBlobs(webPartManager, path, userName, sharedDataBlob, userDataBlob)
        End Sub
    
        Protected Overrides Sub SavePersonalizationBlob(ByVal webPartManager As System.Web.UI.WebControls.WebParts.WebPartManager, ByVal path As String, ByVal userName As String, ByVal dataBlob() As Byte)
            Dim impersonatedName As String = MySession.UserLoginName()
            path = path & "|" & impersonatedName
            userName = impersonatedName
            MyBase.SavePersonalizationBlob(webPartManager, path, userName, dataBlob)
        End Sub
    End Class
    

    And then in web.config:

    <system.web>
      <webParts>
        <personalization defaultProvider="AspNetSqlPersonalizationProvider">
          <providers>
            <remove name="AspNetSqlPersonalizationProvider"/>
            <add name="AspNetSqlPersonalizationProvider"
                 type="MyProject.MySqlPersonalizationProvider"
                 connectionStringName="MyConnectionString"
                 applicationName="/"></add>
          </providers>
        </personalization>
      </webParts>
    
      <profile enabled="true" defaultProvider="TableProfileProvider">
        <providers>
          <clear />
          <add name="TableProfileProvider" type="Microsoft.Samples.SqlTableProfileProvider" connectionStringName="iCaseHomepage" table="aspnet_Profile" applicationName="/" />
        </providers>
      </profile>
    </system.web>
    <connectionStrings>
      <remove name="LocalSqlServer"/>
      <add name="MyConnectionString" connectionString="Data Source=MyServerName;Initial Catalog=MyDatabaseName;Integrated Security=True" providerName="System.Data.SqlClient"/>
    </connectionStrings>
    

    and on the page:

            <asp:WebPartManager ID="WebPartManager1" runat="server" >
                <Personalization Enabled="True" />
            </asp:WebPartManager>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble figuring out this issue I'm having with cookies and asp.net applications.
I'm having trouble figuring out a way to conditionally cancel an asp:TextBox's OnTextChanged AutoPostBack
I am having trouble figuring out how to implement this. I am returning user
I am having trouble figuring out how to make text found using glob into
I'm having trouble figuring out the proper way to update nested data using Google
I'm having trouble figuring out how to make a GET request using RestSharp on
I'm having trouble figuring out databases in VB.NET. (VS 2008) What control(s) do I
I'm having trouble figuring out the proper way of using pythons unittest framework I
I'm having trouble figuring out how to do this using Rails, though it is
im having trouble figuring out how to bind mouseout() to my entire nav bar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.