-->

SerializationException上,当用户在ASP.NET被拒绝“CustomIdent

2019-09-23 16:21发布

我尝试实现ASP.NET身份验证和授权对我们现有的数据库之上。 我们有一个网站调用Web服务来获取其数据。 要使用web服务,我需要提供用户名和密码。 知道了,我决定实施的IIdentity和IPrincipal的存储加密的密码,并能够执行web服务调用时提供。 在未来,我们可能要使用更多的内置asp.net的安全,所以我实现了成员资格和角色提供并覆盖正是我需要(的ValidateUser和GetRoles)虽然,用户验证感谢向会员提供后实现我还是我自己CustomIdentity设置为Context.User是能够在需要时找回密码。

如允许用户访问该网页它,只要正常使用。 但是当用户被拒绝,而不是抛出一个AccessDeniedException,框架洒在我的CustomIdentity一个序列化异常。 我发现了一个与此链接描述更多的细节完全类似的行为 ,但没有答案已张贴。

我的例外是完全一样上面的链接


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

它是正确使用成员和自定义的IIdentity和IPrincipal的在同一时间? 如果不是,如果我使用会员和角色提供其中添加像密码或其他用户数据属性?

最好的祝福,

斯特凡Erbrech

Answer 1:

经过一番更多的测试,据我贴所说的链接,看来,当我从Visual Studio调试模式下运行该错误只发生。 如果我设置的项目在IIS中运行,则错误不见了,安全实现将按预期。

---那是在轻量级的Web服务器中的错误在Visual Studio中实现呢?---

编辑:您可以去您的Web项目的属性,进入“网络”选项卡,并选中“使用本地IIS服务器”。 然而,这将要求您运行Visual Studio作为管理员,并有在计算机上安装IIS,以便VS可以在本地IIS服务器创建虚拟目录时加载的项目。



Answer 2:

就我而言,我只是必须要继承MarshalByRefObject

public class IcmtrIdentity :  MarshalByRefObject, IIdentity
{
   ...
}


Answer 3:

这可能不是正确的答案,但我有这个问题,但也固定它。

本来,我只是说继承了自定义类GenericIdentity (或implimented IIdentity )。 当我终于创建了继承了一个自定义类GenericPrincipal (或implimented IPrincipal ),那么它的所有工作?

CustomPrincipal类什么也没做,但是从继承GenericPrincipal并有一个构造函数调用基类的构造。

无论是CustomPrincipalCustomIdentity类没有任何impliment SerializationISerializable东西。 再说,我的课都是很基本的。



Answer 4:

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

试图运行使用CustomIdentity Web应用程序时,我有同样的问题。 为了将项目设置为使用IIS在VS 2008中,你需要将URL定义你的应用程序池在Web应用程序项目。



Answer 5:

这也可以通过添加包含您的开发机器上的自定义身份到GAC大会决定。



文章来源: SerializationException on 'CustomIdentity' when user is denied in ASP.NET