小编Gus*_*tav的帖子

ASP.NET MVC 5 - 身份.如何获取当前的ApplicationUser

我的项目中有一个Article实体,其中包含ApplicationUser名为的属性Author.如何获取当前记录的完整对象ApplicationUser?在创建新文章时,我必须将Author属性设置Article为当前属性ApplicationUser.

在旧的成员机制中它很简单,但在新的身份识别方法中,我不知道如何做到这一点.

我试着这样做:

  • 为身份扩展添加using语句: using Microsoft.AspNet.Identity;
  • 然后我尝试获取当前用户: ApplicationUser currentUser = db.Users.FirstOrDefault(x => x.Id == User.Identity.GetUserId());

但我得到以下异常:

LINQ to Entities无法识别方法'System.String GetUserId(System.Security.Principal.IIdentity)'方法,并且此方法无法转换为商店表达式.来源=的EntityFramework

c# identity asp.net-mvc-5 asp.net-identity

229
推荐指数
6
解决办法
29万
查看次数

npm 被杀死或 errno 137

我知道已经有很多关于这个问题的问题,但我简直不敢相信我的内存不足。

npm run dev

> mdbvue@4.8.1 dev /usr/www/users/****/****
> node build/dev-server.js

> Starting dev server...
? ?wdm?: wait until bundle finished:
Killed
npm ERR! code ELIFECYCLE
npm ERR! errno 137
npm ERR! mdbvue@4.8.1 dev: `node build/dev-server.js`
npm ERR! Exit status 137
npm ERR!
npm ERR! Failed at the mdbvue@4.8.1 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: …
Run Code Online (Sandbox Code Playgroud)

npm laravel vue.js

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

线程“主”中的异常java.lang.IllegalArgumentException:无法实例化接口org.springframework.context.ApplicationContextInitializer

我遇到以下错误:

线程“主”中的异常java.lang.IllegalArgumentException:无法实例化接口org.springframework.context.ApplicationContextInitializer:org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer位于org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:414) org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:385)上的org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:394)org.springframework.boot.SpringApplication.initialize(SpringApplication.java:261)在org.springframework.boot.SpringApplication。(SpringApplication.java:237)在org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)在org。springframework.boot.SpringApplication.run(SpringApplication.java:1180)

我的主要方法是

package proj1;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;

@SpringBootApplication
public class WebApplication extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(WebApplication.class);
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(WebApplication.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

我的pom.xml是

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.webapp</groupId>
  <artifactId>proj1</artifactId>
  <packaging>war</packaging>
  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.5.RELEASE</version>
    </parent>
  <version>0.0.1-SNAPSHOT</version>
  <name>proj1 Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
   <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.0.0.RELEASE</version>
        </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
     <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-autoconfigure</artifactId>
    <version>1.4.0.RELEASE</version>
</dependency> 
    <dependency> …
Run Code Online (Sandbox Code Playgroud)

java spring-boot

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

画布的 .MoveUp 使用什么值

下面的代码将 PDF 文件中的所有页面复制到一个新文件中,并在第一页的顶部插入一个带有红色边框的矩形,其中包含一个短文本。

如果我不移动它,顶部会留下一个缺口(这里放大了很多,字体大小只有8):

在此处输入图片说明

但是,如果我将矩形向上移动4的经验值:

    iText.Kernel.Geom.Rectangle pageSize = firstPage.GetCropBox().MoveUp(4);
Run Code Online (Sandbox Code Playgroud)

顶部会有一个完美的匹配:

在此处输入图片说明

值 4 与字体大小无关。

我不喜欢代码中的幻数,所以我的问题是:为什么是 4?什么表达式会揭示这个值 4?

代码行在此处的第一种方法中。第二个是使用它的地方,第三个是从第一个调用的;它只是提供一种风格:

private static void RegisterDocument(PdfDocument pdfDocument, string registration)
{
    // Magic value to close gap between top of page and top of rectangle with the registration.
    const float moveUp = 4F;

    Document document = new Document(pdfDocument, new PageSize(PageSize.A4));
    PdfPage firstPage = document.GetPdfDocument().GetFirstPage();

    Paragraph paragraph = new Paragraph(registration).AddStyle(RegistrationStyle());

    iText.Kernel.Geom.Rectangle pageSize = firstPage.GetCropBox().MoveUp(moveUp);
    LayoutContext layoutContext = new LayoutContext(new LayoutArea(1, pageSize));
    IRenderer renderer …
Run Code Online (Sandbox Code Playgroud)

.net c# pdf itext7

6
推荐指数
1
解决办法
120
查看次数

MDB协议(多点总线)-C#串行端口通信

我正在开发C#中的MDB软件作为付款阅读器媒体,该媒体通过MDB协议与自动售货机进行通信。目前一切正常,我可以与自动售货机进行通讯。在阅读了MDB协议之后,通信就像预期的一样,但是我在理解某些命令/响应时遇到了麻烦。

我只是有一个问题,关于我应该发回自动售货机的回复,可能真的很愚蠢,但是我真的不明白应该如何发送。

如MDB协议所示,当我从MDB机器获得轮询并且读取器(我的计算机)的状态为“会话空闲”时,我可以向自动售货机发送“开始会话”命令。这些命令以字节为单位通过串行端口发送,并在MDB协议中显示为十六进制或二进制。BEGIN SESSION命令应包含以下内容:

Z1开始会议Z2-Z3可用资金Z4-Z7付款媒体ID Z8付款类型Z9-Z10付款数据

我了解Z1-Z7是因为在MDB协议中有很好的示例,但是我在理解Z8-Z10(付款类型和付款数据)时遇到了麻烦。

MDB协议说明以下内容:
“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“” “”“”“” 
Z8:付款方式:
00xxxxxxb =普通自动售货卡(请参阅EVA-DTS标准附录A.1.1定义)
x1xxxxxxb =测试媒体 
1xxxxxxxb =免费售货卡 
xx000000b -0 VMC默认价格
xx000001b -1用户组(Z9 = EVA-DTS元素DA701) 
             价目表编号(Z10 = EVA-DTS元素LA101)* 
xx000010b 
           -2用户组(Z9 = EVA-DTS元素DA701)
            折扣组索引(Z10 = EVA-DTS元素MA403) 
xx000011b 
           -3折扣百分比系数(Z9 = 00,Z10 = 0至100 **,
            报告为EVA-DTS元素MA404中的正值) 
xx000100b 
           -4附加费百分比系数(Z9 = 00,Z10 = 0到100 **,
            报告为EVA-DTS元素MA404中的负值) 


*用户组是所有授权用户的细分。 
它允许选择性的成本分配。 
用户组通常与价目表没有直接关系。 
价目表是价格表。 
每个价目表包含每种产品的单独价格。 
折扣组指示将在其中应用百分比系数的价格清单。 
如果VMC不知道用户组,价格表或折扣组, 
使用正常价格(Z8默认为00h)。 
Z9和Z10的最小值为0。 

**百分比以二进制表示(00到64h) 

注意:并非所有VMC都支持这些功能。 

Z9-Z10:如上定义的付款数据
“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“” “”“”“”

有人可以告诉我如何将Z8和Z9-Z10发送到自动售货机。现在,我一直在发送(以十六进制表示):“ 0x02(Z8),0x10(Z9)和0x10(Z10)”,这只是一个疯狂的猜测,它正在起作用。真的不知道为什么,但是可能不正确。

Z8和Z9-Z10应该如何发送?

c# multidrop-bus

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

无法在http:// localhost上启动驱动程序服务

我想寻求帮助,因为我在没有界面的Windows服务器上运行硒时遇到了以下错误:

无法 在OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)的OpenQA.Selenium.Remote.Remote.RemoteWebDriver.Execute(String)的http:// localhost:49906 /处的OpenQA.Selenium.DriverService.Start()上启动驱动程序服务在OpenQA.Selenium.Chrome.ChromeDriver.OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(DriverCommandToExecute,Dictionary`2 parameters)在OpenQA。 (ChromeDriverService服务,ChromeOptions选项,TimeSpan commandTimeout)位于OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions选项)

.net c# selenium windows-server selenium-chromedriver

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

日期选择器不显示

我正在创建一个 MS Access 2016 数据库。在一张表中,它有两个日期字段和一个时间字段。在表格格式中,两个日期字段都设置为“显示日期选择器”属性设置为“日期”。此外,在使用这两个字段的表单上,这些字段都设置为“日期”。问题是日期选择器仅显示一个,尽管所有属性都相同,当然字段名称除外。我已经调整了页面大小和字段大小,但似乎没有任何帮助。有没有人见过这个问题?任何想法我能做什么?

ms-access date ms-access-2013

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

C#Datatable转换为IList

我使用以下代码转换DatasetIList.有没有更好的方法来编写下面的代码:

IList lst = new List<object>();
var tbl = dsList.Tables[0];
foreach (DataRow dr in tbl.Rows)
{
   lst.Add(dr.ItemArray);
}
Run Code Online (Sandbox Code Playgroud)

c#

0
推荐指数
1
解决办法
1650
查看次数

IsNull(x)和x =""之间有区别吗?

在if语句中我总是必须使用 if isnull(x) or x = "" then

这两者之间的区别是什么?为什么它们在某些情况下都不起作用?

vba access-vba

0
推荐指数
1
解决办法
104
查看次数

如何跟踪引发异常的行

try
{
    //This code BlockLine no 1Line no 2Line no 3etc
}
catch (Exception ex) 
{
    LblError.Text= ex.Message + ex.InnerException.Message
}
Run Code Online (Sandbox Code Playgroud)

我有一个try catch块的代码.该try块有多行代码.我想知道try块中存在哪一行引发异常.

c# asp.net exception

0
推荐指数
1
解决办法
43
查看次数