Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Serialization '上的序列化异常;CustomIdentity';在ASP.NET中拒绝用户时_Serialization_Asp.net Membership_Iprincipal_Iidentity_Access Denied - Fatal编程技术网

Serialization '上的序列化异常;CustomIdentity';在ASP.NET中拒绝用户时

Serialization '上的序列化异常;CustomIdentity';在ASP.NET中拒绝用户时,serialization,asp.net-membership,iprincipal,iidentity,access-denied,Serialization,Asp.net Membership,Iprincipal,Iidentity,Access Denied,我尝试在现有数据库的基础上实现ASP.NET身份验证和授权。 我们有一个网站调用webservice来获取其数据。要使用webservice,我需要提供用户名和密码。 知道了这一点,我决定实现IIdentity和IPrincipal来存储加密的密码,并能够在执行webservice调用时提供密码。 将来,我们可能希望更多地使用asp.net的内置安全性,因此我实现了成员资格和角色提供程序,并覆盖了我所需要的内容(ValidateUser和GetRoles) 不过,在通过成员资格提供程序实现验证用

我尝试在现有数据库的基础上实现ASP.NET身份验证和授权。 我们有一个网站调用webservice来获取其数据。要使用webservice,我需要提供用户名和密码。 知道了这一点,我决定实现IIdentity和IPrincipal来存储加密的密码,并能够在执行webservice调用时提供密码。 将来,我们可能希望更多地使用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
同时使用会员资格、自定义身份和i原则是否正确? 如果没有,如果使用成员资格和角色提供程序,在哪里添加密码或其他用户数据等属性

致以最良好的祝愿


Stephane Erbrech

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

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

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

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


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

这可能不是正确的答案,但我也有这个问题,但已经解决了

最初,我只是有一个继承了
genericantity
(或实现了
IIdentity
)的自定义类。当我最终创建了一个继承了
GenericPrincipal
(或实现了
IPrincipal
)的自定义类时,它是否一切正常

我的
CustomPrincipal
类除了继承自
GenericPrincipal
之外什么都不做,并且有一个称为基构造函数的构造函数


CustomPrincipal
CustomIdentity
类都没有实现任何
Serialization
ISerializable
内容。同样,我的类都是非常基本的。

在我的例子中,我只需要从
MarshalByRefObject
继承

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

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

@serbrech:如果您愿意重新阅读您的问题,您肯定会注意到您没有发布异常。事实上,请花点时间发布完整的异常,方法是捕获它,然后发布
ex.ToString()
的结果。只要添加我得到的异常,如果helps@serbrech:谢谢。您的
CW.CustomAuthentication.CWIdentity
可序列化吗?您是否测试过它可以使用
二进制格式化程序
进行序列化?@serbrech:很抱歉,这让人很痛苦。我发现您无法捕获此异常以显示
ex.ToString()
。但是,您是否可以查看服务器事件日志以查看是否存在来自“ASP.NET”事件源的警告事件?其中一些可能包含完整的异常或其他有用的信息。经过更多测试后,根据我发布的链接所述,似乎只有在我从visual studio以调试模式运行时才会发生此错误。如果我将项目设置为在IIS中运行,那么错误就消失了,安全实现也会按预期工作。这是Visual studio中实现的轻量级Web服务器中的一个bug吗?因此解决方案是添加
[Serializable]
?:blush:我现在记不起来了-那是很久以前的事了。这取决于您在
CustomPrincipal
或(更可能)您的“CustomIdentity”中放置的内容。如果你在那里保存一个自定义类,那么是的。。我想我不得不这么做。我已经将我的
CustomIdentity
类剥离为只包含字符串、int或基元类型。有人知道为什么会出现这种情况吗?