asp.net – 无法将’System.Web.Profile.DefaultProfile’类型的
发布时间:2020-12-16 10:00:10 所属栏目:asp.Net 来源:网络整理
导读:我看到这个错误: 无法将类型为“System.Web.Profile.DefaultProfile”的对象强制转换为“ProfileCommon”. 在以下代码: ProfileCommon p =(ProfileCommon)ProfileCommon.Create(TextUsername.Text,true); 我不确定为什么…… 解决方法 同意theChrisKent.它
我看到这个错误:
无法将类型为“System.Web.Profile.DefaultProfile”的对象强制转换为“ProfileCommon”. 在以下代码: ProfileCommon p =(ProfileCommon)ProfileCommon.Create(TextUsername.Text,true); 我不确定为什么…… 解决方法
同意theChrisKent.它看起来像web.config中的问题
查看以下示例,如何在asp.net中获取ProfileCommon对象 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="GetProfile" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> User Name:<asp:TextBox ID="txtUserName" runat="server"/> <asp:Button ID="cmdGet" runat="server" OnClick="cmdGet_Click" Text="Get Profile" /><br /> <asp:Label ID="lbl" runat="server" Text=""/> </div> </form> </body> </html> 文件:Default.aspx.cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class GetProfile : System.Web.UI.Page { protected void cmdGet_Click(object sender,EventArgs e) { ProfileCommon profile = Profile.GetProfile(txtUserName.Text); if (profile.LastUpdatedDate == DateTime.MinValue) { lbl.Text = "No user match found."; } else { lbl.Text = "This user lives in " + profile.FirstName; } } } 文件:Web.config <?xml version="1.0"?> <configuration> <system.web> <profile> <properties> <add name="FirstName" type="String" serializeAs="Binary"/> <add name="LastName" type="String" serializeAs="Xml"/> <add name="DateOfBirth" type="DateTime" serializeAs="String"/> </properties> </profile> </system.web> </configuration> 编辑 此示例仅在项目类型为website时才有效.如果要在Web应用程序中使用ProfileCommon对象,请通过以下链接 Converting Profile Object Code 编辑-II 根据您的评论,以下链接可能会对您有所帮助 ASP.NET Profiles in Web Application Projects (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc-4 – 尝试从Visual Studio 2012项目目录运行站
- asp.net-mvc-3 – 在MVC3中添加有关打印功能的数据
- 使用一般处理程序HTTPHandler下载文件
- asp.net-mvc-5 – 我应该如何从JsonResult控制器返回404?
- asp:Repeater 添加button 事件
- 如何利用ETW(Event Tracing for Windows)记录日志
- asp.net-mvc-4 – 编辑并继续不在Windows 7,32位操作系统上
- asp.net-mvc – Ninject MVC和WCF扩展不能与InRequestScope
- asp.net-mvc-2 – 允许匿名访问Content和Script文件夹
- asp.net-mvc-4 – 如何将新的支付网关集成到[NopCommerce 3
推荐文章
站长推荐
- asp.net-mvc – ASP MVC 3在不同的视图中使用不同
- azure – 创建App Service订阅EMPTY
- asp.net – 我可以在超链接上显式指定NavigateUr
- asp.net-mvc – 在cshtml中折叠C#块并保存
- asp.net-mvc – 新ASP.NET MVC 6身份中AspNetUse
- ASP.Net自定义会话状态管理
- ASP.NET Repeater以及分页控件AspNetPager
- asp.net-mvc – MVC视图| *你如何*处理IsAuthent
- 在运行时期间在ASP.NET Web API中控制[JsonIgnor
- asp.net-mvc – 并不总是创建__RequestVerificat
热点阅读