Search

Using Custom Identities in ASP.NET fails when using the ASP.NET Developement Server by Paulo Morgado

Closed
as Won't Fix Help for as Won't Fix

26
0
Sign in
to vote
Type: Bug
ID: 274696
Opened: 4/29/2007 12:32:09 PM
Access Restriction: Public
4
Workaround(s)
19
User(s) can reproduce this bug
When using custom identities (classes that implement System.Security.Principal.IIdentity) and the ASP.NET Development Server a SerializationException is thrown.
Details (expand)
Product Language
English

Version

Visual Studio Code Name "Orcas" (Beta 1)
Operating System
Windows Server 2003
Operating System Language
English
Steps to Reproduce
Run the attached web site and log in and out (user="user, password="password"). It might not happen always, but if you keep trying it will happen.
Actual Results
Exception is thrown.

Event Type:    Warning
Event Source:    ASP.NET 2.0.50727.0
Event Category:    Web Event
Event ID:    1309
Date:        29-04-2007
Time:        18:34:54
User:        N/A
Computer:    ORCASBETA1VSTS

Description:
Event code: 3005

Event message: An unhandled exception has occurred.
Event time: 29-04-2007 18:34:54
Event time (UTC): 30-04-2007 1:34:54
Event ID: 8afb62b7b7604da087509636bb48fbad

Event sequence: 16

Event occurrence: 1

Event detail code: 0


Application information:
Application domain: 53ad158c-10-128223704725800576
Trust level: Full
pplication Virtual Path: /WebSite3
Application Path: C:\Documents and Settings\Administrator\My Documents\Visual Studio Codename Orcas\WebSites\WebSite3\
Machine name: ORCASBETA1VSTS


Process information:
Process ID: 3880
Process name: WebDev.WebServer.EXE
Account name: ORCASBETA1VSTS\Administrator

Exception information:
Exception type: SerializationException
Exception message: Type is not resolved for member 'MyIdentity,App_Code.4broaqvc, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.


Request information:
Request URL: http://localhost:1137/WebSite3/default.aspx
Request path: /WebSite3/default.aspx
User host address: 127.0.0.1
User: user
Is authenticated: True
Authentication Type: test
Thread account name: ORCASBETA1VSTS\Administrator

Thread information:
Thread ID: 4
Thread account name: ORCASBETA1VSTS\Administrator
Is impersonating: False

Stack trace:
at Microsoft.VisualStudio.WebHost.Connection.ReadRequestBytes(Int32 maxBytes)
at Microsoft.VisualStudio.WebHost.Request.ReadEntityBody(Byte[] buffer, Int32 size)
at System.Web.HttpRequest.GetEntireRawContent()
at System.Web.HttpRequest.FillInFormCollection()
at System.Web.HttpRequest.get_Form()
at System.Web.HttpRequest.get_HasForm()
at System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull)
at System.Web.UI.Page.DeterminePostBackMode()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Expected Results
None. Should work just like when using IIS
TAP Code (if applicable)
 
      You can indicate your satisfaction with how Microsoft handled this issue by completing this quick 3 question survey. [Details]

 

Sign in to post a comment.
Posted by BaggaDonuts on 6/28/2012 at 2:18 PM
Here's how you fix this issue. First, mark your class as Serializable. then implement the ISerializable interface:

/// <summary>
/// Stubs identity for offline authentication
/// </summary>
[Serializable]
public class StubIdentity : IIdentity, ISerializable

...

public void GetObjectData(SerializationInfo info, StreamingContext context)
{
    if (context.State == StreamingContextStates.CrossAppDomain)
    {
        GenericIdentity gIdent = new GenericIdentity(this.Name, this.AuthenticationType);
        info.SetType(gIdent.GetType());

        System.Reflection.MemberInfo[] serializableMembers;
        object[] serializableValues;

        serializableMembers = FormatterServices.GetSerializableMembers(gIdent.GetType());
        serializableValues = FormatterServices.GetObjectData(gIdent, serializableMembers);

        for (int i = 0; i < serializableMembers.Length; i++)
        {
            info.AddValue(serializableMembers[i].Name, serializableValues[i]);
        }
    }
    else
    {
        throw new InvalidOperationException("Serialization not supported");
    }
}
Posted by jvella1975 on 6/27/2012 at 4:29 AM
Come on microsoft .. this bug has existed for five years and through 3 (about to be 4) versions of visual studio ... fix it or explain why you won't/can't.

"Your feedback improving Microsoft products" <-- yeah .. apparently not so much :(
Posted by Reto Ghioldi on 5/21/2012 at 12:58 AM
"We will consider this issue again in a future release."...

Will this issue be fixed in Visual Studio 11? Hope so! :-)
Posted by BLoritsch on 10/5/2010 at 11:29 AM
This problem not only still exists, it also affects IPrincipal classes. When your IPrincipal is implemented using Linq to Entities, none of the provided workarounds can work. I can't change the inheritance hierarchy to include MarshalByRefObject. The IIdentity workaround no longer works because it is an IPrincipal. And I'm using C#, not VB so that workaround does not work.

If this bug cannot be fixed, it would help to understand what is preventing the ASP.NET development server from functioning properly.
Posted by mt1337 on 3/19/2010 at 10:48 AM
Oh I see MS has closed the issue and has no interest in fixing it "for this release" (whatever that means).

How cute.
Posted by mt1337 on 3/19/2010 at 10:47 AM
Is Microsoft going to fix this bug, EVER? It's 2010, and VS 2008 with SP1 has the issue still.
Posted by Travis Illig on 1/29/2010 at 3:38 PM
This happens while using Microsoft.IdentityModel.Claims.ClaimsPrincipal, too. Apparently claims-based auth systems won't be supported on the dev server.
Posted by Microsoft on 6/29/2007 at 3:36 PM
Thank you for your feedback. We are aware of this issue and are not planning to address this in the ASP.NET Development Server for this release. We will consider this issue again in a future release.

The Web Tools Team
Posted by Microsoft on 5/3/2007 at 1:23 PM
Thanks for submitting this issue. We are investigating.

The Web Tools Team
Posted by Microsoft on 4/29/2007 at 11:32 PM
Thanks for your feedback. We have reproduced this bug on Win2003 SP2 and OrcasBeta1VSTS, and we are sending this bug to the appropriate group within the Visual Studio Product Team for triage and resolution. Thank you, Visual Studio Product Team.
Posted by Microsoft on 4/29/2007 at 6:31 PM
Thank you for your feedback. We are currently investigating. If this issue is urgent, please call support directly (see http://support.microsoft.com). Thank you, Visual Studio Product Team.
Posted by Paulo Morgado on 4/29/2007 at 2:13 PM
If anyone wants to try this, he/she can read this blog post (http://msmvps.com/blogs/paulomorgado/archive/2007/04/29/bug-using-custom-identities-in-asp-net-fails-when-using-the-asp-net-developement-server.aspx) and download the sample.
Sign in to post a workaround.
Posted by BaggaDonuts on 6/28/2012 at 2:19 PM
Here's how you fix this issue. First, mark your class as Serializable. then implement the ISerializable interface:

/// <summary>
/// Stubs identity for offline authentication
/// </summary>
[Serializable]
public class StubIdentity : IIdentity, ISerializable

...

public void GetObjectData(SerializationInfo info, StreamingContext context)
{
    if (context.State == StreamingContextStates.CrossAppDomain)
    {
        GenericIdentity gIdent = new GenericIdentity(this.Name, this.AuthenticationType);
        info.SetType(gIdent.GetType());

        System.Reflection.MemberInfo[] serializableMembers;
        object[] serializableValues;

        serializableMembers = FormatterServices.GetSerializableMembers(gIdent.GetType());
        serializableValues = FormatterServices.GetObjectData(gIdent, serializableMembers);

        for (int i = 0; i < serializableMembers.Length; i++)
        {
            info.AddValue(serializableMembers[i].Name, serializableValues[i]);
        }
    }
    else
    {
        throw new InvalidOperationException("Serialization not supported");
    }
}
Posted by simbolo on 3/22/2009 at 6:33 PM
When using a custom IIdentity, the following will produce a SerializationException on the ASP.NET Development Server (VS2008).

Dim UserIP as String = HttpContext.Current.Request.UserHostAddress

I would except the UserIP to become something like "127.0.0.1".

Workaround...
Dim UserIP as String="127.0.0.1"
dim HostName as string= HttpContext.Current.Request.Url.Host.ToString.ToLower
If Not Hostname = "localhost" Then
UserIP = HttpContext.Current.Request.UserHostAddress
End If
Posted by Leandro Díaz Guerra on 12/18/2007 at 9:56 AM
Another possibility, which works great even if it adds a small performance drop, is to make the class heritate from MarshalByRefObject. If you do this, it will work correctly in both Cassini and IIS.
Posted by ps279 on 9/19/2007 at 12:34 AM
Implement ISerializable on your IIdentity class. Implement GetObjectData with code like this:

if (IsSet(context.State, StreamingContextStates.CrossAppDomain))
{
    info.SetType(typeof(GenericIdentity));
    info.AddValue("m_name", name);
    info.AddValue("m_type", AUTHENTICATIONTYPE);
    return;
}

This seems to be good enough to get my app running on the ASP.NET development server. This may have unpredictable effects in other environments.