我想一般扁平一些json所以我可以转换为数据表并使用c#绑定到数据网格
什么是最好的办法,记住我不知道我要下多少级别?
例如
{ "appointmentid": 4, "policyid": 1, "guid": "00000000-0000-0000-0000-000000000000", "number": "1234567890", "ampm": "false", "date": "2015-09-08T00:00:00", "vehicle": { "id": 1, "guid": "00000000-0000-0000-0000-000000000000", "make": null, "model": null }, "installer": { "installerid": "1", "name": "Installer 1", "contact": "qwerty", "qascore": "0", "address1": "qwerty", "address2": "qwerty", "address3": null, "address4": null, "city": "qwertyu", "county": "qwertyu", "postcode": "asdfghj", "country": "GB", "email": "asdfghj", "web": "asdfghjk", "archived": false }, "installations": [ { "installationid": 6, "installationstatus": { "installationstatusid": 4, "installationstatus": "FAIL" }, "isactive": true }, { "installationid": 7, "installationstatus": …
我正在努力将log4net添加到我的MVC5项目中.我做了以下事情;
安装包log4net
已成功安装(我假设)log4net
我已将以下内容添加到cofiguration部分中的web.config中;
<log4net debug="true">
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="Logs\ApiLog.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
Run Code Online (Sandbox Code Playgroud)
我在web.config中的configSections中添加了以下内容;
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
Run Code Online (Sandbox Code Playgroud)
我已将以下内容添加到我的Global.asax中
log4net.Config.XmlConfigurator.Configure();
Run Code Online (Sandbox Code Playgroud)
解决方案编译,但是当我尝试运行我的程序时,我得到错误;
HTTP错误500.19 - 内部服务器错误
无法访问请求的页面,因为页面的相关配置数据无效.
无法读取配置节'log4net',因为它缺少节声明
有没有人有任何我做错的事吗?
我有一个API端点,它返回一个循环错误(因为它链接一个循环返回的连接类),所以例如
class A
{
virtual ClassAB;
}
class B
{
virtual ClassAB;
}
class AB
{
virtual ClassA;
virtual ClassB;
}
Run Code Online (Sandbox Code Playgroud)
在API GET中,我需要从ClassA的角度返回ClassB的细节(反之亦然,在ClassB GET中).
当我得到时,我做了以下事情:
IQueryable<ClassA> results = _dbset
.Include(x => x.ClassAB)
.Include(x => x.ClassAB.Select(y => y.ClassB))
.AsExpandable()
.Where(predicate)
.OrderBy(x => x.ID);
Run Code Online (Sandbox Code Playgroud)
所以我得到自我循环错误.现在在我的数据库上下文中我有:
Configuration.ProxyCreationEnabled = false;
Configuration.LazyLoadingEnabled = false;
Run Code Online (Sandbox Code Playgroud)
在我的Global.asax
protected void Application_Start()
身上:
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
Run Code Online (Sandbox Code Playgroud)
但是,我仍然得到错误; 任何想法如何解决这个问题?
我正在尝试使用mat-autocomplete
类似于以下示例的过滤器;
所以我试图实现这个功能,这样当用户开始输入交易时,他们正在寻找基于字符串中任何地方的部分字符串匹配的过滤器,并在选项中突出显示.
我目前在我的.html中
<mat-form-field class="form-group special-input">
<input type="text" placeholder="Select a trade" aria-label="Select a trade" matInput [formControl]="categoriesCtrl" [matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete" md-menu-class="autocomplete">
<mat-option *ngFor="let option of filteredOptions | async" [value]="option.name">
{{ option.name }}
</mat-option>
</mat-autocomplete>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
我的.ts在哪里
categoriesCtrl: FormControl;
filteredOptions: Observable<ICategory[]>;
options: ICategory[];
categorySubscription: Subscription;
constructor(fb: FormBuilder, private router: Router, private service: SearchService, private http: Http) {
this.categoriesCtrl = new FormControl();
}
ngOnInit() {
this.categorySubscription = this.service.getCategories().subscribe((categories: ICategory[]) => {
this.options = categories;
this.filteredOptions = this.categoriesCtrl.valueChanges
.pipe(
startWith(''),
map(options …
Run Code Online (Sandbox Code Playgroud) 出于某种原因,迁移历史记录表已从我们的测试数据库中删除.
为了解决这个问题,我从以前的备份恢复了表.然而,我们错过了一些迁移.为了应用这些,我注释掉了所有的up()方法代码.然后运行它们(在我运行更新历史表之后,想法是评论)
但是我得到了错误
缺少System.xml.xmlexception根元素
有任何想法吗?显然,在这种情况下up方法是空的.
我的中有以下内容appSetting.json
;
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"MailServiceSettings": {
"SmtpServer": "<server>",
"ToAddresses": [
"email@domain.com",
"email2@domain.com"
],
"UserName": "username",
"Password": "password"
}
}
Run Code Online (Sandbox Code Playgroud)
而appSettings.Development.json
我也有了微妙的变化;
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"MailServiceSettings": {
"SmtpServer": "<server>",
"ToAddresses": [
"development@domain.com"
],
"UserName": "username",
"Password": "password"
}
}
Run Code Online (Sandbox Code Playgroud)
这样我就可以在本地主机中发送邮件发件人设置文本,而无需轰炸实时邮箱。
但是,当我在调试中运行时,设置appSettings.json
将被注入而不是appSettings.Development.json
.
我的Program.cs
是使用默认的WebHostBuilder
;
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args)
.Build().Run(); …
Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的 WebApi注入SignInManager<ApplicationUser>
并AspNetUserManager<ApplicationUser>
注入我的刷新令牌中间件。只是为了不我使用身份,所以我的ApplicationUser
班级是
public class ApplicationUser : IdentityUser<int>, IEntity
在我的中间件构造函数中,我有;
private readonly AuthService _service;
public TokenProviderMiddleware(
RequestDelegate next,
Func<IMyDataContext> context,
SignInManager<ApplicationUser> signInManager,
AspNetUserManager<ApplicationUser> userManager)
{
_next = next;
_serializerSettings = new JsonSerializerSettings
{
Formatting = Formatting.Indented
};
_service = new AuthService(context, signInManager, userManager);
}
Run Code Online (Sandbox Code Playgroud)
在我的 Startup.cs 中,我有以下内容;
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<MyDataContext>(
options => options.UseSqlServer(DbGlobals.DevDatabase));
services.AddTransient<IMyDataContext, MyDataContext>();
services.AddTransient<Func<IMyDataContext>>(provider => () => provider.GetService<IMyDataContext>());
services.AddIdentity<ApplicationUser, ApplicationRole>()
.AddEntityFrameworkStores<BemfeitoDataContext>()
.AddDefaultTokenProviders();
services.Configure<IdentityOptions>(options =>
{
// Password settings
options.Password.RequireDigit = …
Run Code Online (Sandbox Code Playgroud) c# dependency-injection asp.net-core asp.net-core-middleware
我目前在application_start中进行了以下设置
log4net.Config.XmlConfigurator.Configure(new FileInfo(Server.MapPath("~/Web.config")));
Run Code Online (Sandbox Code Playgroud)
现在为了然后注销到log4net我需要向每个控制器添加一个实例;
public static readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Run Code Online (Sandbox Code Playgroud)
因为这是我想在整个api中使用的东西.我可以在global.asax中声明这个,这样我就可以调用;
logger.Error( "输出");
什么时候需要?
我对如何使用asp.net core 2和EntityFrameworkCore 2记录生成的SQL以及正确的处理方法感到有些困惑。
从MS docs 阅读此链接后,我应该在startup.cs
using 中的服务配置过程中添加.UseLoggerFactory(<LoggerFactory>)
。
但是,这似乎已过时,因为当我希望添加记录器时,会收到此消息。
有人可以告诉我添加记录器以记录SQL以便进行调试的最佳方法吗?
我还计划继续使用Nlog进行所有日志记录,而不是使用内置的日志记录工具,我假设这样做的方法(因为注入了Nlog loggerfactory而不是默认的MS实例),所以方法相同或存在配置差异(关于使用NLog)?
在我们的Asp.Net Core API
应用程序中,我们使用EPPlus
. 从数据库中添加数据并用于.GetAsByteArray()
返回生成的 Excel 文件。
I now need give the user the ability to download this file as a PDF as well. However, the documentation seems limited on this.
I found the following link here;
However, this doesn't use the official EPPlus repo.
I am currently using EPPlus v 5.2.0
.
Is it possible for me to convert the ExcelPackage
to a PDF byte array without saving the file to …
c# ×8
asp.net-core ×4
asp.net-mvc ×2
log4net ×2
angular ×1
epplus ×1
json ×1
json.net ×1
nlog ×1
typescript ×1