GVKun编程网logo

asp.net – 无法将’System.Web.Profile.DefaultProfile’类型的对象强制转换为’ProfileCommon’类型

14

关于asp.net–无法将’System.Web.Profile.DefaultProfile’类型的对象强制转换为’ProfileCommon’类型的问题就给大家分享到这里,感谢你花时间阅读本站内容

关于asp.net – 无法将’System.Web.Profile.DefaultProfile’类型的对象强制转换为’ProfileCommon’类型的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于.net – ‘System.Windows.Data.Binding’类型的对象无法转换为’System.String’类型、/ profiles / user-profile / UserProfile上的DidsNotExist不存在匹配查询、/etc/profile和~/.bash_profile等文件的区别和联系、asp.net – MVC-Mini-Profiler – Web窗体 – 找不到/ mini-profiler-results等相关知识的信息别忘了在本站进行查找喔。

本文目录一览:

asp.net – 无法将’System.Web.Profile.DefaultProfile’类型的对象强制转换为’ProfileCommon’类型

asp.net – 无法将’System.Web.Profile.DefaultProfile’类型的对象强制转换为’ProfileCommon’类型

我看到这个错误:

无法将类型为“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

.net – ‘System.Windows.Data.Binding’类型的对象无法转换为’System.String’类型

.net – ‘System.Windows.Data.Binding’类型的对象无法转换为’System.String’类型

我想知道是否有人可以帮忙.我现在已经半天不停地反对这个问题了,我一定是做错了.我有一个具有许多依赖项属性的自定义控件.

[TemplatePart(Name = informationBubble.informationBubbleTitlePart,Type = typeof(TextBlock))]
[TemplatePart(Name = informationBubble.informationBubbleProductimagePart,Type=typeof(Image))]

public class informationBubble : Control 
{
    #region Template Parts Name Constants

    /// <summary>
    /// Name constant for the information Bubble Title Part
    /// </summary>
    public const string informationBubbleTitlePart = "informationBubbleTitleText";

    /// <summary>
    /// Name constant for the information Bubble Product Image Part
    /// </summary>
    public const string informationBubbleProductimagePart = "informationBubbleProductimage";

    #endregion

    #region TemplateParts

    private TextBlock _Title;

    internal TextBlock Title
    {
        get { return _Title; }
        private set
        {
            _Title = value;

            if (_Title != null)
            {
                _Title.Text = this.ProductTitleText;       
            }
        }
    }

    private Image _Productimage;

    internal Image Productimage
    {
        get { return _Productimage; }
        private set
        {
            _Productimage = value;

            if (_Productimage != null)
            {
                _Productimage.source = this.ProductimageSource;
            }
        }
    }

    #endregion

    #region Public String Product Title 

    // Dependency properties declaration
    public static readonly DependencyProperty ProductTitleProperty = DependencyProperty.Register(
        "ProductTitle",typeof(string),typeof(informationBubble),new PropertyMetadata(string.Empty,new PropertyChangedCallback(OnProductTitleChanged)));

    public static void OnProductTitleChanged(DependencyObject sender,DependencyPropertyChangedEventArgs e)
    {
        informationBubble iBubble = sender as informationBubble;

        if (iBubble.Title != null)
        {
            iBubble.Title.Text = e.NewValue as string;
        }
    }

    public string ProductTitleText
    {
        get { return GetValue(ProductTitleProperty) as string; }
        set { SetValue(ProductTitleProperty,value); }
    }

    #endregion

    #region Public Image Source Product Image

    public static readonly DependencyProperty ProductimageSourceProperty = DependencyProperty.Register(
        "ProductimageSource",typeof(ImageSource),new PropertyMetadata(null,new PropertyChangedCallback(OnProductimageSourceChanged)));

    public static void OnProductimageSourceChanged(DependencyObject sender,DependencyPropertyChangedEventArgs e)
    {
        informationBubble iBubble = sender as informationBubble;

        if (iBubble.Productimage != null)
        {
            iBubble.Productimage.source = e.NewValue as ImageSource;
        }
    }

    public ImageSource ProductimageSource
    {
        get { return GetValue(ProductimageSourceProperty) as ImageSource; }
        set { SetValue(ProductimageSourceProperty,value); }
    }

    #endregion

    public informationBubble()
    {
         this.DefaultStyleKey = typeof(informationBubble);
    }

    #region Overrides

    public override void OnApplyTemplate()
    {       
        base.OnApplyTemplate();

        Title = GetTemplateChild(informationBubble.informationBubbleTitlePart) as TextBlock;
        Productimage = GetTemplateChild(informationBubble.informationBubbleProductimagePart) as Image;
    }

    #endregion

    #region Private Methods

    private void GoToState(string stateName,bool useTransitions)
    {
        visualstatemanager.GoToState(this,stateName,useTransitions);
    }

    #endregion
}

现在,如果我在我的xaml中的某个地方使用此控件,那么如果我执行此操作:

<controls:informationBubble 
        ProductimageSource="{Binding SelectedItem.normalImageSource}"
        ProductTitleText="Test Title"
        "/>

但是,如果我尝试将数据绑定到viewmodel中的SelectedItem对象的title属性的数据:

<controls:informationBubble 
            ProductimageSource="{Binding SelectedItem.normalImageSource}"
            ProductTitleText="{Binding SelectedItem.Title,Mode=TwoWay"
            "/>

我得到’System.Windows.Data.Binding’类型的对象不能转换为’System.String’类型. TextBlock的text属性是DependencyProperty,所​​以我必须在这里遗漏一些明显的东西.

非常感谢任何帮助或见解.

短剑的一种

解决方法

可能是该物业的名称是错误的.下面代码中的“ProductTitle”应该是“ProductTitleText”吗?

public static readonly DependencyProperty ProductTitleProperty = DependencyProperty.Register(
    "ProductTitle",// "ProductTitleText" ?
    typeof(string),new PropertyChangedCallback(OnProductTitleChanged)));

我想当你使用字符串常量时,WPF使用反射直接访问属性“public string ProductTitleText”. DependencyProperty被忽略,因为属性的名称不匹配(“ProductTitle”与“ProductTitleText”).

因此,对于标题,您有一个名为“ProductTitle”的依赖项属性和一个名为“ProductTitleText”的(字符串)属性.
对于Productimage,您有一个名为“ProductimageSource”的依赖项proeprty和一个名为“ProductimageSource”的属性(ImageSource类型).

是否有意义?

/ profiles / user-profile / UserProfile上的DidsNotExist不存在匹配查询

/ profiles / user-profile / UserProfile上的DidsNotExist不存在匹配查询

它将呈现末尾的空格。因此,模板应如下所示:

#                                                                 no space ↓
<input type='hidden' name='username' value="{% if username %}{{ username }}{% else %}{{ testuser }}{% endif %}">

/etc/profile和~/.bash_profile等文件的区别和联系

/etc/profile和~/.bash_profile等文件的区别和联系

对比说明:
/etc/profile:为系统的每个用户设置环境信息和启动程序,当用户第一次登录时,该文件被执行,其配置对所有登录的用户都有效。当被修改时,必须重启才会生效。英文描述:”System wide environment and startup programs, for login setup.”

/etc/environment:系统的环境变量,/etc/profile是所有用户的环境变量,前者与登录用户无关,后者与登录用户有关,当同一变量在两个文件里有冲突时,以用户环境为准。

/etc/bashrc:为每个运行 bash shell 的用户执行该文件,当 bash shell 打开时,该文件被执行,其配置对所有使用bash的用户打开的每个bash都有效。当被修改后,不用重启只需要打开一个新的 bash 即可生效。英文描述:”System wide functions and aliases.”

~/.bash_profile:为当前用户设置专属的环境信息和启动程序,当用户登录时该文件执行一次。默认情况下,它用于设置环境变量,并执行当前用户的 .bashrc 文件。理念类似于 /etc/profile,只不过只对当前用户有效,也需要重启才能生效。(注意:Centos7系统命名为.bash_profile,其他系统可能是.bash_login或.profile。)

~/.bashrc:为当前用户设置专属的 bash 信息,当每次打开新的shell时,该文件被执行。理念类似于/etc/bashrc,只不过只对当前用户有效,不需要重启只需要打开新的shell即可生效。

~/.bash_logout:为当前用户,每次退出bash shell时执行该文件,可以把一些清理工作的命令放进这个文件。

/etc/profile.d/:此文件夹里是除/etc/profile之外其他的”application-specific startup files”。英文描述为”The /etc/profile file sets the environment variables at startup of the Bash shell. The /etc/profile.d directory contains other scripts that contain application-specific startup files, which are also executed at startup time by the shell.” 同时,这些文件”are loaded via /etc/profile which makes them a part of the bash “profile” in the same way anyway.” 因此可以简单的理解为是/etc/profile的一部分,只不过按类别或功能拆分成若干个文件进行配置了(方便维护和理解)。

注意事项
以上需要重启才能生效的文件,其实可以通过source xxx暂时生效。

文件的执行顺序为:当登录Linux时,首先启动/etc/environment和/etc/profile,然后启动当前用户目录下的~/.bash_profile,执行此文件时一般会调用~/.bashrc文件,而执行~/.bashrc时一般会调用/etc/bashrc,最后退出shell时,执行~/.bash_logout。简单来说顺序为:

登录时)/etc/environment –> /etc/profile(以及/etc/profile.d/里的文件) –> ~/.bash_profile –> (打开shell时)~/.bashrc –> /etc/bashrc –> (退出shell时)~/.bash_logout
————————————————
版权声明:本文为CSDN博主「siberiawolf61」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u010048823/article/details/51871825

asp.net – MVC-Mini-Profiler – Web窗体 – 找不到/ mini-profiler-results

asp.net – MVC-Mini-Profiler – Web窗体 – 找不到/ mini-profiler-results

我试图让MVC-mini-profiler与webforms一起工作。

的NuGet
我已经安装了Nuget软件包。

PM> Install-Package MiniProfiler


我在网站的头部有这个。

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<%= MvcMiniProfiler.MiniProfiler.RenderIncludes() %>

DAL
我在一个功能中使用它作为POC。这不在Global.asax(我不知道是否需要)

profiler = MiniProfiler.Start();

using (profiler.Step("Im doing stuff"))
{
   //do stuff here
}

MvcMiniProfiler.MiniProfiler.Stop();

结果
它呈现< div class =“profiler-results left”>< / div>标签在我的页面,但它是空的。

如果我看着chrome控制台,我看到一个404试图找到:http://example.com/mini-profiler-results?id=339d84a7-3898-429f-974b-64038462d59a&popup=1


我错过了一个让/ mini-profiler-results链接工作的一步吗?

回答
我标记为答案的答复使我认为它与我的配置无关(这是真的)。我正在使用Umbraco 4.7.0。我必须在我的web.config中添加“〜/ mini-profiler-results”到umbracoReservedUrls和umbracoReservedpaths。

解决方法

在安装NuGet软件包之后,以下页面对我来说非常棒:
<%@ Page Language="C#" %>
<%@ Import Namespace="MvcMiniProfiler" %>
<%@ Import Namespace="System.Threading" %>

<script type="text/c#" runat="server">
    protected void Page_Load(object sender,EventArgs e)
    {
        MiniProfiler.Start();
        using (MiniProfiler.Current.Step("I'm doing stuff"))
        {
            Thread.Sleep(300);
        }
        MiniProfiler.Stop();
    }
</script>

<!DOCTYPE html>
<html>
<head runat="server">
    <title></title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
    <%= MiniProfiler.RenderIncludes() %>
</head>
<body>
    <form id="Form1" runat="server">
        <div>Hello World</div>
    </form>
</body>
</html>

今天关于asp.net – 无法将’System.Web.Profile.DefaultProfile’类型的对象强制转换为’ProfileCommon’类型的讲解已经结束,谢谢您的阅读,如果想了解更多关于.net – ‘System.Windows.Data.Binding’类型的对象无法转换为’System.String’类型、/ profiles / user-profile / UserProfile上的DidsNotExist不存在匹配查询、/etc/profile和~/.bash_profile等文件的区别和联系、asp.net – MVC-Mini-Profiler – Web窗体 – 找不到/ mini-profiler-results的相关知识,请在本站搜索。

本文标签: