我需要能够使用Kestrel Web服务器在默认url /下提供我的'index.html' .现在我只能使用完整路径(即/index.html)访问我的静态文件
同样,这在VisualStudio上完美运行,上下文是OSX与Kestrel
这是我的Startup.cs
public void ConfigureServices(DI.IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles();
app.UseMvc();
}
Run Code Online (Sandbox Code Playgroud)
我到目前为止的解决方案是在HomeController中进行重定向.但这很简单,我试图提供一个静态的html文件,老实说我不希望它由我的应用程序处理,如果可能直接从Kestrel服务.
macos asp.net-mvc asp.net-core-mvc kestrel-http-server asp.net-core
我正在使用ASP.NET Core MVC应用程序,我的连接字符串存在问题.
我在生产服务器上ASPNETCORE_ENVIRONMENT设置了一个变量Production,我的生产服务器是运行IIS的Windows Server 2012R2.我还在生产服务器上安装了DotNetCore.1.0.4_1.1.1-WindowsHosting.exe.
在开发过程中,我UserSecrets用来保存我的连接字符串.这工作正常.
对于生产,我希望我的生产服务器上的环境变量中的连接字符串,这是我遇到问题的地方.我怀疑它可能是我构建环境变量的方式.
当我尝试在生产中访问数据库时,我得到一个错误,表明它无法解析连接字符串.
An exception occurred in the database while iterating the results of a query.
System.ArgumentException: Keyword not supported: '"server'.
at System.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2
parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms)
at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms)
at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
Run Code Online (Sandbox Code Playgroud)
如果我将连接字符串放入appSettings.json,生产服务器就可以正常工作.
所以,这是我的appSettings.json文件示例,显示了在生产中工作的连接字符串;
{
"ConnectionStrings": {
"TestDb": "Server=TestServer;Database=TestDb;Persist Security Info=True;User ID=TestUser;Password=testpassword;MultipleActiveResultSets=true"
},
...
...
...
}
}
Run Code Online (Sandbox Code Playgroud)
如果我将此appSettings.json文件部署到生产中,它可以正常工作.
在我的ASP.Net Core应用程序中,在Startup.cs文件中,我有以下内容:
public Startup(IHostingEnvironment env)
{
var …Run Code Online (Sandbox Code Playgroud) 我在EF Core数据模型中使用了我自己的类的属性.
public class Currency
{
public string Code { get; set; }
public string Symbol { get; set; }
public string Format { get; set; }
}
[ComplexType]
public class Money
{
public int? CurrencyID { get; set; }
public virtual Currency Currency { get; set; }
public double? Amount { get; set; }
}
public class Rate
{
public int ID { get; set; }
public Money Price = new Money();
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,当我尝试创建迁移时,EF Core报告错误.
Microsoft.Data.Entity.Metadata.ModelItemNotFoundException: The entity type …Run Code Online (Sandbox Code Playgroud) 与Kestrel http服务器相比,IIS的性能如何?
似乎Kestrel受到异步和事件驱动的服务器框架系列的启发.与此同时,IIS具有悠久的开发历史,并且在功能方面显然更加成熟.综合考虑所有这些因素,我特意寻找内存利用率,线程利用率,请求相关比较(如每秒请求数)和流功能的比较.
我想从AWS Amazon Linux AMI实例运行.NET Core MVC网站.
以下是我到目前为止采取的步骤:
sudo yum update -ysudo yum install libunwind -ysudo yum install gettext -ycurl -sSL https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview1/scripts/obtain/dotnet-install.sh | bash /dev/stdin --version 1.0.0-preview1-002702 --install-dir ~/dotnetsudo ln -s ~/dotnet/dotnet /usr/local/bincurl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.shsource /home/ec2-user/.dnx/dnvm/dnvm.sh我有一个客户需要填写的表格.提交表单后,我想将表单的索引视图(名字,姓氏,电话号码等)中的基本信息发送到电子邮件.我目前正在使用GoDaddy作为我的托管网站.这有关系,还是我可以直接从我的MVC应用程序发送电子邮件?我的模型,视图,控制器有以下内容.我以前从未这样做过,我真的不确定如何去做.
模型:
public class Application
{
public int Id { get; set; }
[DisplayName("Marital Status")]
public bool? MaritalStatus { get; set; }
[Required]
[DisplayName("First Name")]
public string FirstName { get; set; }
[DisplayName("Middle Initial")]
public string MiddleInitial { get; set; }
[Required]
[DisplayName("Last Name")]
public string LastName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
控制器:
public ActionResult Index()
{
return View();
}
// POST: Applications/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for …Run Code Online (Sandbox Code Playgroud) 有问题的结构/类:
public struct HttpMethod
{
public static readonly HttpMethod Get = new HttpMethod("GET");
public static readonly HttpMethod Post = new HttpMethod("POST");
public static readonly HttpMethod Put = new HttpMethod("PUT");
public static readonly HttpMethod Patch = new HttpMethod("PATCH");
public static readonly HttpMethod Delete = new HttpMethod("DELETE");
private string _name;
public HttpMethod(string name)
{
// validation of name
_name = name.ToUpper();
}
public static implicit operator string(HttpMethod method)
{
return method._name;
}
public static implicit operator HttpMethod(string method)
{
return new HttpMethod(method); …Run Code Online (Sandbox Code Playgroud) 在dotnet core 2.0控制台应用程序中,输出:
Console.WriteLine("Hello World from "+ System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription);
Run Code Online (Sandbox Code Playgroud)
是一个意想不到的价值:
Hello World from .NET Core 4.6.00001.0
Run Code Online (Sandbox Code Playgroud)
有没有办法以编程方式检测.net core 2.0或更高版本,而不是2.0之前的.net核心平台?我意识到在大多数情况下你可能不应该这样做.但是在你确实需要这样做的奇怪情况下,你会怎么做?
我有一个 ASP.NET Core 3.0 应用程序。在 Startup 类中,在方法中
public void ConfigureServices(IServiceCollection services)
Run Code Online (Sandbox Code Playgroud)
我想配置身份验证,以便 JWT 由我的 ISecurityTokenValidator 实现处理:CustomJwtSecurityTokenHandler。为此,我需要获取实现类的实例 CustomJwtSecurityTokenHandler,其构造函数需要注入一些服务。出于这个原因,我需要打电话:
var serviceProvider = services.BuildServiceProvider();
Run Code Online (Sandbox Code Playgroud)
为了创建一个“临时” serviceProvider 来获取我的带有注入参数的 CustomJwtSecurityTokenHandler 实例。
我最终得到了这个代码(效果很好!):
services.AddAuthentication(authenticationOptions =>
{
authenticationOptions.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
authenticationOptions.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(jwtBearerOptions =>
{
jwtBearerOptions.SecurityTokenValidators.Clear();
CustomJwtSecurityTokenHandler customJwtSecurityTokenHandler;
{
// create a temporary serviceProvider, in order to retrieve a CustomJwtSecurityTokenHandler (supposed to be registered as addin!).
var serviceProvider = services.BuildServiceProvider();
customJwtSecurityTokenHandler = serviceProvider.GetService<CustomJwtSecurityTokenHandler>();
}
//below line adds the custom validator class
jwtBearerOptions.SecurityTokenValidators.Add(customJwtSecurityTokenHandler);
});
Run Code Online (Sandbox Code Playgroud)
只是,从方法 ConfigureServices 中调用 …
c# ×4
asp.net-core ×3
asp.net-mvc ×2
.net-core ×1
amazon-ec2 ×1
class ×1
iis ×1
linux ×1
macos ×1
mysql ×1
performance ×1
php ×1
sendmail ×1
struct ×1