我正在开发一个ASP.NET MVC 4项目,包含NHibernate 3.3.我有两个声明如下的类(简化为简洁):
public class LocationReading
{
public long Timestamp { get; set; }
public GeoLocation Location { get; set; }
}
public class GeoLocation
{
public double Latitude { get; set; }
public double Longitude { get; set; }
}
public class RoutePoint
{
public virtual int Id { get; set; }
public virtual string Username { get; set; }
public virtual LocationReading LocationReading { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
并映射如下:
<class name="RoutePoint">
<id name="Id" type="Int32" column="id" unsaved-value="0">
<generator …Run Code Online (Sandbox Code Playgroud) 我要实现的目标是:当有人访问时:smartphone.webshop.nl/home/index
我想将其从中间件重定向到:webshop.nl/smartphone/home/index
我要这样做是因为我想创建一个通用控制器,该控制器从上从数据库获取数据sub-domein。因此,我需要所有呼叫都到达同一控制器。
现在这是我的中间件:
public Task Invoke(HttpContext context)
{
var subDomain = string.Empty;
var host = context.Request.Host.Host;
if (!string.IsNullOrWhiteSpace(host))
{
subDomain = host.Split('.')[0]; // Redirect to this subdomain
}
return this._next(context);
}
Run Code Online (Sandbox Code Playgroud)
我如何重定向以及我的controller/mvc配置应如何显示?
我对.net core来说还很陌生,因此请在回答中明确说明。谢谢。
我有一个 aspnet core 应用程序,我正在尝试配置 serilog 来向我发送电子邮件,但没有成功。
我有这样的配置:
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.File("1.log", LogEventLevel.Information, fileSizeLimitBytes: 10_000_000, rollOnFileSizeLimit: true, shared: true)
.WriteTo.Email(new EmailConnectionInfo
{
FromEmail = "xxx@gmail.com",
ToEmail = "yyy@gmail.com",
MailServer = "smtp.gmail.com",
NetworkCredentials = new NetworkCredential
{
UserName = "user",
Password = "pass"
},
EnableSsl = true,
Port = 587,
EmailSubject = "Error in app"
}, restrictedToMinimumLevel: LogEventLevel.Error, batchPostingLimit: 1)
.CreateLogger();
Run Code Online (Sandbox Code Playgroud)
没有电子邮件。它写入文件,因此记录器处于活动状态。我缺少什么吗?
我正在尝试运行update-database以迁移我对数据库所做的一些更改。
一切顺利,直到出现以下错误:
找不到适合实体类型“ReportType”的构造函数。以下构造函数的参数无法绑定到实体类型的属性:无法绑定 'id', 'name' in 'ReportType(string id, string name)'。
这是 ReportType.cs 的代码:
public class ReportType : SmartEnum<ReportType, string>
{
public static readonly ReportType ReportType1 = new ReportType("Blah", "Blah");
public static readonly ReportType ReportType2 = new ReportType("Blah", "Blah");
public static readonly ReportType ReportType3 = new ReportType("Blah", "Blah");
// required for EF, but breaking for SmartEnum
// private ReportType() {}
private ReportType(string id, string name) : base(name, id)
{
}
}
Run Code Online (Sandbox Code Playgroud)
正如您在该代码的注释部分所看到的,拥有无参数构造函数通常可以解决 EF Core 的这个问题,但 SmartEnum 没有无参数构造函数基础。
2018 年 …
c# entity-framework entity-framework-core asp.net-core entity-framework-migrations
我想在返回表单操作后删除临时文件。我如何使用 ASP.NET Core 实现这一点:
public IActionResult Download(long id)
{
var file = "C:/temp/tempfile.zip";
var fileName = "file.zip;
return this.PhysicalFile(file, "application/zip", fileName);
// I Would like to have File.Delete(file) here !!
}
Run Code Online (Sandbox Code Playgroud)
文件太大,无法使用内存流返回。
Startup.cs 有一些方法可用于配置 swagger 以添加文件上传功能,现在我可以在 .NET Framework 中的哪个文件中执行相同的功能?
我只是在学习 .NET Core 和 GraphQL,无法从网络上获得一个示例(我已经尝试了十几个)来工作。他们都在使用这个库https://graphql-dotnet.github.io,每次我尝试使用有效的 GraphQL 查询访问端点时,我都会得到以下响应:
{
"errors": [
{
"message": "Unmapped selection Field",
"extensions": {
"code": "EXECUTION_ERROR"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
示例之一:https : //github.com/mmacneil/ASPNetCoreGraphQL
我似乎找不到任何谷歌搜索该错误的内容,并且有关该错误的文档没有太多帮助。我希望有人与图书馆合作并遇到同样的问题。
这是在 GraphQLController 中执行查询的结果的错误:
InnerException = {GraphQL.ExecutionError: Unmapped selection Field
at GraphQL.Language.CoreToVanillaConverter.Selection(ASTNode source)
at GraphQL.Language.CoreToVanillaConverter.SelectionSet(GraphQLSelectionSet source)
at GraphQL.Language.CoreToVanillaConverter.Operation(GraphQLOperationDefinition source)
at GraphQL.Language.CoreToVanillaConverter.AddDefinitions(GraphQLDocument source, Document target)
at GraphQL.Language.CoreToVanillaConverter.Convert(String body, GraphQLDocument source)
at GraphQL.Execution.GraphQLDocumentBuilder.Build(String body)
at GraphQL.DocumentExecuter.ExecuteAsync(ExecutionOptions options)
Run Code Online (Sandbox Code Playgroud)
这也是我在这里的第一篇文章。如果您需要更多信息,请告诉我。
我知道这个问题似乎已经有人问过了,但这与 ASP.NET Core 而不是 ASP.NET 5 有关。
当用户关闭浏览器选项卡时,我试图让用户注销;我正在 MacOS 上使用 Chrome 和 Safari 对此进行测试。
目前,当我登录用户并关闭并重新打开浏览器选项卡时,用户保持登录状态。
当我登录用户在我设定的是AuthenticationProperties IsPersistent要false。然而,当浏览器选项卡关闭时,用户在 Chrome 和 Safari 上都保持登录状态。(浏览器没有关闭,只有选项卡)。
Task task = HttpContext.SignInAsync(principal,
new AuthenticationProperties
{
IsPersistent = false
});
await task;
Run Code Online (Sandbox Code Playgroud)
根据文档:persistent-cookies
“您可能希望 cookie 在浏览器会话中持续存在”
在上述情况下,我将 IsPersistent 设置为 false,并且我假设 cookie 不应在会话中存活。
据我了解,浏览器不会关闭会话,服务器会关闭,并且设置为以下 10 秒。
然而,通过如下测试,我无法让用户注销。
这可能无关紧要...... Starup.cs 有这个:
services.AddSession(options =>
{
// Set a short timeout for easy testing.
options.IdleTimeout = TimeSpan.FromSeconds(10);
options.Cookie.HttpOnly = …Run Code Online (Sandbox Code Playgroud) 我使用的是HostedService内部的ASP.NET core web api,将在部署在IIS的前提实例(.NET Core 2.2)我需要确保空闲超时设置为零,以确保后台服务将持续运行,我相信这可以通过设置空闲来完成应用程序池上的超时为零。但是,这将需要IIS管理员在设置时执行此操作,所以我想知道是否有办法在 kestrel 首次在CreateWebHostBuilder()程序类的方法中配置时配置其空闲超时为零.
这可能吗?
我见过一个类似这样的函数:
function
{
[CmdletBinding()]
[OutputType([Boolean])]
param (
[bool] $param
}
# ...
}
Run Code Online (Sandbox Code Playgroud)
Boolean和之间有什么区别bool?
c# ×9
asp.net-core ×7
.net ×2
asp.net-mvc ×2
boolean ×1
entity-framework-migrations ×1
graphql ×1
kestrel ×1
linq ×1
nhibernate ×1
powershell ×1
serilog ×1
swagger ×1
swagger-ui ×1