GVKun编程网logo

c# – UserControl中的EF无法看到app.config?(framework.c.exe无法找到入口)

19

在本文中,我们将带你了解c#–UserControl中的EF无法看到app.config?在这篇文章中,我们将为您详细介绍c#–UserControl中的EF无法看到app.config?的方方面面,

在本文中,我们将带你了解c# – UserControl中的EF无法看到app.config?在这篇文章中,我们将为您详细介绍c# – UserControl中的EF无法看到app.config?的方方面面,并解答framework.c.exe无法找到入口常见的疑惑,同时我们还将给您一些技巧,以帮助您实现更有效的.net – WCF何时使用app.config或web.config?、.net – 捕获UserControl中的KeyDown事件、500 OOPS: cannot open config file:/etc/vsftpd/userconfig/****、Asp.net UserControl LoadControl问题

本文目录一览:

c# – UserControl中的EF无法看到app.config?(framework.c.exe无法找到入口)

c# – UserControl中的EF无法看到app.config?(framework.c.exe无法找到入口)

我刚刚创建了一个用户控件.
此控件还使用我的静态实体框架类来加载两个组合框.
一切都很好,运行没有问题.设计和运行时正在运行.
然后,当我停止应用程序时,包含我的UserControl的所有表单在设计时不再有效.我只看到两个错误:

ERROR1:
指定的命名连接在配置中找不到,不打算与EntityClient提供程序一起使用,或者无效.

错误2:
变量ccArtikelVelden要么是未声明的,要么是从未分配过的.
(ccArtikelVelde是我的UserControl)

运行时一切都还在运行

我的静态EF Repositoy类:

public class BSManagerData
{
    private static BSManagerEntities _entities;
    public static BSManagerEntities Entities
    {
        get
        {
            if (_entities == null)
                _entities = new BSManagerEntities();
            return _entities;
        }
        set
        {
            _entities = value;
        }
    }
}

我的UserControl中发生了一些逻辑,用于加载组合框中的数据:

private void LaadCbx()
{
    cbxCategorie.DataSource = (from c in BSManagerData.Entities.Categories
                               select c).ToList();
    cbxCategorie.displayMember = "Naam";
    cbxCategorie.ValueMember = "Id";
}

private void cbxCategorie_SelectedindexChanged(object sender,EventArgs e)
{
    cbxFabrikant.DataSource = from f in BSManagerData.Entities.Fabrikants
                              where f.Categorie.Id == ((Categorie)cbxCategorie.SelectedItem).Id
                              select f;
    cbxFabrikant.displayMember = "Naam";
    cbxFabrikant.ValueMember = "Id";
}

使表单再次工作的唯一方法是设计时间,即在UserControl中注释掉EF部分(见上文)并重建.
这很奇怪,一切都在同一个程序集中,相同的命名空间(为了简单起见).

有人有想法吗?

解决方法

看起来你在设计模式下以某种方式执行数据库代码.为了防止这种情况,请搜索导致此问题的控件和方法,并使用:
if (DesignMode)
    return

此外,静态缓存数据库上下文是一个非常糟糕的主意.它会导致多线程问题,以及进行插入和删除时的问题.数据库上下文用于单个“工作单元”,添加2,删除3个其他对象并调用SaveChanges一次.

.net – WCF何时使用app.config或web.config?

.net – WCF何时使用app.config或web.config?

我正在研究WCF应用程序.我很困惑何时在WCF客户端和服务中使用web.config文件和app.config文件.任何人都可以帮我什么时候使用app.config和何时使用web.config.

解决方法

它是用IIS托管的吗? Web.config文件.它是作为独立服务托管的吗? App.config中.

http://msdn.microsoft.com/en-us/library/ms733932.aspx

.net – 捕获UserControl中的KeyDown事件

.net – 捕获UserControl中的KeyDown事件

我有一个带有几个子控件的用户控件.我需要用户界面来响应按键,所以我决定将处理代码放在MainControl_KeyDown事件中.但是,当我在我的应用程序中按下某个键时,此事件不会触发.

我通过一个依赖于使用Windows API的搜索引擎找到了一个解决方案,我希望避免使用它,因为对于.NET框架正确支持的功能而言似乎有些过分.

解决方法

您可以为用户控件中的每个子控件添加一个KeyDown事件处理程序,并在每个控件中触发用户控件的KeyDown事件,如下所示:
private void textBox1_KeyDown(object sender,KeyEventArgs e)
{
    this.OnKeyDown(e);
}

500 OOPS: cannot open config file:/etc/vsftpd/userconfig/****

500 OOPS: cannot open config file:/etc/vsftpd/userconfig/****

各位大哥,麻烦看看这是撒情况?登录的时候不定时会报这个错。userconfig下的文件已经是777了。

下面是详细配置:

# Example config file /etc/vsftpd.conf

#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd''s
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd''s)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
data_connection_timeout=60
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that turning on ascii_download_enable enables malicious remote parties
# to consume your I/O resources, by issuing the command "SIZE /big/file" in
# ASCII mode.
# These ASCII options are split into upload and download because you may wish
# to enable ASCII uploads (to prevent uploaded scripts etc. from breaking),
# without the DoS risk of SIZE and ASCII downloads. ASCII mangling should be
# on the client anyway..
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd.banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd.chroot_list
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list

#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
ls_recurse_enable=YES

pam_service_name=vsftpd
userlist_enable=YES
#enable for standalone mode
listen=YES
tcp_wrappers=YES
ftpd_banner=Authorized uses only. All activity may be monitored and reported.
chroot_local_user=YES
anon_umask=022
#userlist_deny=NO

user_config_dir=/etc/vsftpd/userconfig
local_root=/tmp/testftp/bossftp

Asp.net UserControl LoadControl问题

Asp.net UserControl LoadControl问题

使用LoadControl(type,Params)时,我遇到了一个问题.让我解释…

我有一个超简单的用户控制(ascx)

<%@ Control Language="C#" AutoEventWireup="True" Inherits="Errordisplay" Codebehind="Errordisplay.ascx.cs" EnableViewState="false" %>

<asp:Label runat="server" ID="lblTitle" />
<asp:Label runat="server" ID="lblDescription" />

与代码(c#)后面:

public partial class Errordisplay : System.Web.UI.UserControl
{

    private Message _ErrorMessage;    

    public Errordisplay()
    {
    }

    public Errordisplay(Message ErrorMessage)
    {
        _ErrorMessage = ErrorMessage;
    }    

    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        if (_ErrorMessage != null)
        {
            lblTitle.Text = _ErrorMessage.Message;
            lblDescription.Text = _ErrorMessage.Description;
        }
    }
}

在我的Web应用程序的其他地方,我将使用以下代码向用户控件添加一个实例:

divValidationIssues.Controls.Add(LoadControl(typeof(Errordisplay),new object[] { MessageDetails }));

我正在使用LoadControl的重载版本,因为我想将Message参数传递给构造函数.所有这一切似乎都可以正常工作.

但是,当在Errordisplay用户控件上触发OnPreRender()时,lblTitle和lblDescription变量都为空,尽管它们具有等价的标记.消息变量已正确填充.

任何人都可以说明为什么会发生这种情况吗?

谢谢

编辑:

为了清楚起见,我还会补充说,正在编程地将用户控件添加到页面的代码正在响应按钮按钮,所以“主机页面”已经通过Init,Page_Load进行,现在正在处理事件处理程序.

我们无法在早期的asp生命周期阶段添加用户控件,因为它们是响应于按钮单击事件而创建的.

解决方法

我也尝试了以下代码 – 它产生相同的结果(即lblTitle和lblDescription都为null)
protected void Page_Load(object sender,EventArgs e)
{
    if (_ErrorMessage != null)
    {
        lblTitle.Text = _ErrorMessage.Message;
        lblDescription.Text = _ErrorMessage.Description;
    }
}

我了解到,LoadControl函数将控件加载到正在包含的页面的当前“状态”中.因此,Init,Page_Load等都作为LoadControl调用的一部分运行.

有趣的是,这个(未回答)asp.net论坛的帖子展现了与我遇到的相同的问题.

MSDN Forums Post

另外 – 从MSDN:

When you load a control into a container control,the container raises all of the added control’s events until it has caught up to the current event. However,the added control does not catch up with postback data processing. For an added control to participate in postback data processing,including validation,the control must be added in the Init event rather than in the Load event.

所以不要LoadControl正确的控制?

编辑:

好的,所以我在这里回答我自己的问题

我找到一个回复​​版本的论坛帖子,我链接到Here上面

基本上,答案是LoadControl(type,params)不能推断“页面前端”ascx来解析,因此它不会打扰任何控件.当您使用LoadControl(“ascx路径”)版本时,它被赋予页面前端,因此执行所有解析和初始化.

总而言之,我需要更改正在控制的代码,并将其拆分成单独的部分.即

Control ErrorCntrl = LoadControl("Errordisplay.ascx");
ErrorCntrl.ID = SomeID;
(ErrorCntrl as Errordisplay).SetErrorMessage = MessageDetail;
diverrorContainer.Controls.Add(ErrorCntrl);

它应该工作正常..它不像我以前的尝试一样整洁,但至少它会工作.

我仍然乐意提出上述建议.

干杯

今天的关于c# – UserControl中的EF无法看到app.config?framework.c.exe无法找到入口的分享已经结束,谢谢您的关注,如果想了解更多关于.net – WCF何时使用app.config或web.config?、.net – 捕获UserControl中的KeyDown事件、500 OOPS: cannot open config file:/etc/vsftpd/userconfig/****、Asp.net UserControl LoadControl问题的相关知识,请在本站进行查询。

本文标签: