代码之家  ›  专栏  ›  技术社区  ›  Stéphane

ASP.NET中拒绝用户时“CustomIdentity”上的序列化异常

  •  8
  • Stéphane  · 技术社区  · 17 年前

    我尝试在现有数据库的基础上实现ASP.NET身份验证和授权。 我们有一个网站调用webservice来获取其数据。要使用webservice,我需要提供用户名和密码。 将来,我们可能希望更多地使用asp.net的内置安全性,因此我实现了成员资格和角色提供程序,并覆盖了我所需要的内容(ValidateUser和GetRoles) 不过,在通过成员资格提供程序实现验证用户后,我仍然将自己的CustomIdentity设置为Context.user,以便在需要时检索其密码。

    只要允许用户访问该页面,它就可以正常工作。但是当用户被拒绝时,框架不会抛出AccessDeniedException,而是对我的CustomIdentity抛出序列化异常。 我找到了一个 perfectly similar behaviour with more details described on this link ,但尚未公布答案。

    我的例外情况与上面的链接完全相同

    
    Type is not resolved for member'CW.CustomAuthentication.CWIdentity,CW.CustomAuthentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    
    Exception Details: System.Runtime.Serialization.SerializationException: Type is not resolved for member 'CW.CustomAuthentication.CWIdentity,CW.CustomAuthentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
    
    Source Error:
    
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
    
    Stack Trace:
    
    [SerializationException: Type is not resolved for member 'CW.CustomAuthentication.CWIdentity,CW.CustomAuthentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.]
       Microsoft.VisualStudio.WebHost.Connection.get_RemoteIP() +0
       Microsoft.VisualStudio.WebHost.Request.GetRemoteAddress() +65
       System.Web.HttpRequest.get_UserHostAddress() +18
       System.Web.HttpRequest.get_IsLocal() +13
       System.Web.Configuration.CustomErrorsSection.CustomErrorsEnabled(HttpRequest request) +86
       System.Web.HttpContext.get_IsCustomErrorEnabled() +42
       System.Web.Configuration.UrlAuthFailedErrorFormatter.GetErrorText(HttpContext context) +16
       System.Web.Security.UrlAuthorizationModule.WriteErrorMessage(HttpContext context) +29
       System.Web.Security.UrlAuthorizationModule.OnEnter(Object source, EventArgs eventArgs) +8777783
       System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
    
    

    如果没有,如果使用成员资格和角色提供程序,在哪里添加密码或其他用户数据等属性?

    顺致敬意,

    5 回复  |  直到 17 年前
        1
  •  8
  •   Stéphane    17 年前

    经过更多的测试后,根据我发布的链接所说,似乎只有当我在VisualStudio的调试模式下运行时才会发生此错误。如果我将项目设置为在IIS中运行,那么错误就消失了,安全实现也会按预期工作。

    ---那么,这是在VisualStudio中实现的轻量级Web服务器中的一个bug吗---

    编辑: 您可以进入web项目的属性,转到“web”选项卡,然后选中“使用本地IIS服务器”。但是,这将要求您以管理员身份运行Visual Studio,并在计算机上安装IIS,以便VS在加载项目时可以在本地IIS服务器中创建虚拟目录。

        2
  •  6
  •   Andrew Barber Eric Lafortune    13 年前

    在我的情况下,我只需要继承 MarshalByRefObject .

    public class IcmtrIdentity :  MarshalByRefObject, IIdentity
    {
       ...
    }
    
        3
  •  4
  •   Pure.Krome    15 年前

    最初,我只是有一个自定义类继承了 GenericIdentity (或实施) IIdentity ).当我最终创建了一个自定义类 GenericPrincipal IPrincipal )然后一切都成功了?

    CustomPrincipal 类除了从 有一个构造函数叫做基构造函数。

    和 CustomIdentity 类没有实现任何功能 Serialization 或 ISerializable

        4
  •  2
  •   Jason Plank Maksim Kondratyuk    15 年前

    您可以进入web项目的属性,转到“web”选项卡,然后选中“使用本地IIS服务器”。但是,这将要求您以管理员身份运行Visual Studio,并在计算机上安装IIS,以便VS在加载项目时可以在本地IIS服务器中创建虚拟目录。

    我在尝试使用CustomIdentity运行web应用程序时遇到了相同的问题。为了将项目设置为在VS 2008中使用IIS,您需要在web应用程序项目中定义应用程序池的URL。

        5
  •  1
  •   squig    13 年前

    这也可以通过将包含自定义标识的程序集添加到dev机器上的GAC来解决。

    推荐文章