小编Gav*_*tes的帖子

Linq选择所有项目匹配数组

我有一个类型的数据集合,IEnumerable<Objects.LabourHours>其中包含各种员工的人工记录.我希望过滤列表并仅返回所选员工的记录,这些记录由int[] employees包含EmployeeIDs 的列表指定.

class LabourHours
{
    public int ID {get;set;}
    public int EmployeeID {get;set;}
    public int HoursWorked {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

我该怎么做?我确信之前已经问过,但我在这里找不到类似的东西.我发现最接近的是用UserID对记录进行分组,这不是我需要的 - 我需要实际的记录.

c# linq

12
推荐指数
1
解决办法
2万
查看次数

加载登录表单时网站速度慢

我有一个我正在开发的ASP.NET MVC网站,我最近将它部署在测试服务器上,以便客户端可以提供一些初步反馈.

我注意到在实时服务器上加载登录表单有相当大的延迟,大约20-30秒.登录后,系统运行正常,并且响应迅速.

如果您注销,并返回登录页面,它再次变慢.

它似乎不是apppool假脱机的问题,因为它每次都发生在页面上,而不仅仅是一次,并且所有项目似乎都在加载.

关于如何调试这个的任何建议?

下面是所有控制器enherit的BaseController,以及帐户登录控制器.

protected override void ExecuteCore()
    {



        if (User.Identity.IsAuthenticated)
        {
            try
            {
                AccountDataContext = new AccountDAL.DataContext(ConfigurationManager.AppSettings["Server"]);
                // set the current user. 
                CurrentUser = AccountDataContext.Users.FirstOrDefault(x => x.Email == User.Identity.Name);
                AccountDataContext.CurrentAccount = CurrentUser.Account;
                ViewBag.CurrentUser = CurrentUser;
                ViewBag.Account = CurrentUser.Account;

                SystemDataContext = new SystemDAL.DataContext(ConfigurationManager.AppSettings["Server"], CurrentUser.Account.Database);

                // setup the account based on the users settings
                ViewBag.Theme = "Default"; // hard coded for now
            }
            catch (Exception)
            {
                // if the previous threw an exception, then the logged in user …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc entity-framework

5
推荐指数
1
解决办法
2292
查看次数

在密码保护的目录中连接到SOAP API时出现问题

我正在尝试使用SOAP访问Magento API.我的代码工作正常,但客户端希望密码保护Magento主文件夹.这样做会破坏对API的访问并导致错误.

文档表明这不是问题,您只需指定用户名/密码,但这不起作用.

我正在使用PHP和IIS,通过Plesk 10设置密码保护.这是否使用基本HTTP身份验证或其他?

我的访问代码是:

$client = new SoapAuthClient($GLOBALS["magento_api_path"],array(  

                            'login'=>"admin", 
                            'password'=>"password" 
                          ) 
                    ); 
$session = $client->login($GLOBALS["magento_api_user"], $GLOABLS["magento_api_password"] ,
                    array(  

                            'login'=>"admin", 
                            'password'=>"password" 
                          ) ); 
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.domain.co.uk/magento/index.php/api/index/index/wsdl/1/' : failed to load external entity "http://www.domain.co.uk/magento/index.php/api/index/index/wsdl/1/" in C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php:20 Stack trace: #0 C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php(20): SoapClient->__call('login', Array) #1 C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php(20): SoapClient->login('backenduser', 'backendwebuser', Array) #2 {main} thrown in C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php on line 20
Run Code Online (Sandbox Code Playgroud)

引用的行是$ client-> login命令.

有什么建议?

php soap magento iis-7.5

4
推荐指数
1
解决办法
6465
查看次数

创建帮助程序以覆盖CheckboxFor

我在我正在开始的新项目中使用bootstrap 5,而不是必须在表单字段周围编写所有脚手架,我决定创建一个包装器来自动为我执行此操作.

我使用了textboxfor,textareafor和dropdownlist的以下语法:

public static MvcHtmlString MyTextBoxFor<TModel, TProperty>(
        this HtmlHelper<TModel> helper, 
        Expression<Func<TModel, TProperty>> expression)
    {
        var stringbuilder = new MvcHtmlString("<div class='form-group'>" +
                                                    helper.LabelFor(expression, new {@class = "col-sm-3 control-label"}) +
                                                    "<div class='col-sm-5'>" +
                                                        helper.TextBoxFor(expression, new {@class = "form-control"}) +
                                                    "</div>" +
                                              "</div>");

        return stringbuilder;
    }
Run Code Online (Sandbox Code Playgroud)

然后可以如下调用:

@FormHelpers.MyTextBoxFor(Html, x => x.Name)

但是,这似乎不适用于checkboxfor:

Error 1 'System.Web.Mvc.HtmlHelper<TModel>' does not contain a definition for 'CheckBoxFor' and the best extension method overload 'System.Web.Mvc.Html.InputExtensions.CheckBoxFor<TModel>(System.Web.Mvc.HtmlHelper<TModel>, System.Linq.Expressions.Expression<System.Func<TModel,bool>>)' has some invalid arguments

如果我TProperty改为bool它将编译,但我在调用此帮助器的行上遇到运行时错误:

CS0411: The type …

c# asp.net-mvc asp.net-mvc-4

4
推荐指数
1
解决办法
4079
查看次数

集合绑定到“模型”超过 MvcOptions.MaxModelBindingCollectionSize (1024)

将超过 1024 个项目的数组提交给控制器(当前为 2,500 个项目)时出现异常。似乎您可以提交的项目数量上限为 1024。

它似乎是在 MvcOptions 中设置的,但是我使用的是 .Net Core 3.0 并使用端点路由,因此我无法通过 UseMVC 访问 MvcOptions。

我怎样才能提高这个限制?

我之前通过添加辅助属性提高了限制,如下所示。但是我不确定我需要在哪里设置这个特定限制 - 它似乎不是 HttpContext.Features 的一部分。

    public void OnAuthorization(AuthorizationFilterContext context)
    {
        var features = context.HttpContext.Features;
        var formFeature = features.Get<IFormFeature>();
        if (formFeature == null || formFeature.Form == null)
        {
            features.Set<IFormFeature>(new FormFeature(context.HttpContext.Request, _formOptions));
        }
    }
Run Code Online (Sandbox Code Playgroud)

.net asp.net-core

2
推荐指数
1
解决办法
1032
查看次数