小编Dav*_*idG的帖子

AspNet上的Kestrel vNext不提供/下的索引页面

我需要能够使用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

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

如何在环境变量中正确存储连接字符串,以便通过生产ASP.Net Core MVC应用程序进行检索

我正在使用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)

c# environment-variables asp.net-core-mvc asp.net-core

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

用PHP清除MySQL表中的数据?

如何使用PHP清除MySQL中一个表中的所有条目?

php mysql

18
推荐指数
5
解决办法
12万
查看次数

在Entity Framework Core中使用[ComplexType]

我在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)

entity-framework-core asp.net-core-mvc

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

IIS与Kestrel性能比较

与Kestrel http服务器相比,IIS的性能如何?

似乎Kestrel受到异步和事件驱动的服务器框架系列的启发.与此同时,IIS具有悠久的开发历史,并且在功能方面显然更加成熟.综合考虑所有这些因素,我特意寻找内存利用率,线程利用率,请求相关比较(如每秒请求数)和流功能的比较.

iis performance kestrel-http-server

18
推荐指数
3
解决办法
2万
查看次数

如何在AWS Linux实例上运行.NET Core MVC站点

我想从AWS Amazon Linux AMI实例运行.NET Core MVC网站.

以下是我到目前为止采取的步骤:

  1. 在Visual Studio 2015中创建模板ASP.NET核心Web应用程序(.NET核心) - C# - MVC Web应用程序项目.在IIS Express中编译并运行应用程序.没有对任何配置进行任何更改(web.confg,project.json等).
  2. 将整个Web应用程序解决方案上传到GitHub.
  3. 启动Amazon Linux AMI(2016.03.2)实例.为简单起见,安全组现在打开"所有流量"访问权限.
  4. 使用PuTTY SSH进入Linux实例.使用ec2-user登录.
  5. 更新实例 sudo yum update -y
  6. 安装libunwind sudo yum install libunwind -y
  7. 安装gettext sudo yum install gettext -y
  8. 安装.NET Core curl -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 ~/dotnet
  9. 链接 sudo ln -s ~/dotnet/dotnet /usr/local/bin
  10. 安装.NET版本管理器(DNVM) curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh
  11. 运行命令 source /home/ec2-user/.dnx/dnvm/dnvm.sh
  12. 安装 …

linux amazon-ec2 asp.net-core-mvc kestrel-http-server

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

如何从MVC 5应用程序发送电子邮件

我有一个客户需要填写的表格.提交表单后,我想将表单的索引视图(名字,姓氏,电话号码等)中的基本信息发送到电子邮件.我目前正在使用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)

asp.net-mvc sendmail

15
推荐指数
3
解决办法
7万
查看次数

将struct更改为sealed类时,隐式转换失败

有问题的结构/类:

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)

c# struct class implicit-conversion

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

检测.net核心2.0

在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核心平台?我意识到在大多数情况下你可能不应该这样做.但是在你确实需要这样做的奇怪情况下,你会怎么做?

c# .net-core .net-core-2.0

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

ASP.NET Core 3.0:禁用 ASP0000 不要在“ConfigureServices”中调用“IServiceCollection.BuildServiceProvider”

我有一个 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# asp.net-core

10
推荐指数
0
解决办法
4713
查看次数