我正在将一些应用程序从ASP.NET 5 beta7迁移到RC1.使用HTTPPlatformHandler我可以运行任何这些ASP.NET 5 RC1应用程序作为IIS站点的根目录.但它们不会作为网站的子目录(右键单击"添加应用程序")运行.完整的回复显示:
HTTP/1.1 404 Not Found
Content-Length: 0
Server: Kestrel
X-Powered-By: ASP.NET
Date: Tue, 24 Nov 2015 14:59:04 GMT
Run Code Online (Sandbox Code Playgroud)
这不是权限问题,因为当应用程序是站点的根目录并使用相同的应用程序池时,路由会成功提供.
应用程序池配置为"无托管代码"和集成管道.
root应用程序的web.config如下所示:
<configuration>
<system.webServer>
<handlers>
<add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="..\approot\web.cmd" arguments="" stdoutLogEnabled="false" stdoutLogFile="..\logs\stdout.log" startupTimeLimit="3600"></httpPlatform>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
对于子应用程序,我必须删除httpplatformhandler处理程序以避免错误"无法添加类型为'add'的重复集合条目,并将唯一键属性'name'设置为'httpplatformhandler'".
现在我们必须使用kestrel/httpplatformhandler,是否可以在站点下作为应用程序运行?
我使用Asp.Net Core RC2和Kestrel作为我的Web服务器.我需要确保使用no-cache标头响应请求(在这种情况下所有这些请求),以便浏览器获得最新版本(而不是304).
在Startup中有没有办法配置Kestrel或将此步骤注入管道?
编辑:在我的情况下,no-store可能是更好的选择:https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching "no-store不允许缓存响应并且必须在每次请求时全部取出."
我希望使用 .NET Core 和 Kestrel Web 服务器动态编码 HTTP 响应。以下代码不起作用,响应无法在浏览器中加载。
var response = context.Response;
if (encodingsAccepted.ToArray().Any(x => x.Contains("gzip")))
{
// Set Gzip stream.
context.Response.Headers.Add("Content-Encoding", "gzip");
// Wrap response body in Gzip stream.
var body = context.Response.Body;
context.Response.Body = new GZipStream(body, CompressionMode.Compress);
}
Run Code Online (Sandbox Code Playgroud) 2016-12-02 02:54:39:180 [WARNING] Microsoft.AspNetCore.Server.Kestrel - Connection processing ended abnormally
Microsoft.AspNetCore.Server.Kestrel.BadHttpRequestException: The input string contains non-ASCII or null characters.
at Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIteratorExtensions.GetAsciiString(MemoryPoolIterator start, MemoryPoolIterator end)
at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame.TakeStartLine(SocketInput input)
at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame`1.<RequestProcessingAsync>d__2.MoveNext()
2016-12-02 09:17:10:819 [ERROR] Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware - An unhandled exception has occurred: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at Gillie.JobCenter.Controllers.WebApi.QuestionnairesController.<SaveConsultant>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) …Run Code Online (Sandbox Code Playgroud) 我想在我的ASP.Net Core 2.0(带有Kestrel Web服务器)应用程序中使用HTTPS。
官方文档使用pfx格式,但是我想直接使用PEM格式(由Let's crypto生成),而无需进行任何转换(至少在我的C#代码之外没有任何转换)。有可能吗?
c# ssl-certificate .net-core kestrel-http-server asp.net-core
我有一个ASP.NET Core 2.0应用程序,启用了内置控制台日志记录.这是WebHost的创建:
var webHost = WebHost.CreateDefaultBuilder(args)
.UseUrls("http://localhost:5002")
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
webHost.Run();
Run Code Online (Sandbox Code Playgroud)
发送HTTP POST请求时,将生成以下日志消息并显示在Console stdout中:
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 POST http://localhost:5002/api/sample application/json 2144
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
Executing action method MyApp.Controllers.SampleController.Post (Model.Solve) with arguments (MyApp.Request.MyRequest) - ModelState is Valid
info: Microsoft.AspNetCore.Mvc.Internal.ObjectResultExecutor[1]
Executing ObjectResult, writing value Microsoft.AspNetCore.Mvc.ControllerContext.
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action MyApp.Controllers.SampleController.Post (MyApp) in 1201.9411ms
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 1446.1907ms 200 application/json; charset=utf-8
Run Code Online (Sandbox Code Playgroud)
作为进入生产的一个要求,我需要所有日志条目都包含一个时间戳:现在,我知道我可以在调用Log()方法时自己提供时间戳,如GitHub ASP.NET Logging存储库中的这个开放性问题所述,但是我应该如何直接在WebHost生成的日志消息上这样做(如上所示)?有没有办法添加时间戳,而不必像在StackOverflow答案中提出的解决方案那样重写完整的自定义Logger ?
谢谢.
我有一个非常基本的自托管.NET核心2.1应用程序,具有以下配置:
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.Build();
host.Run();
}
}
Run Code Online (Sandbox Code Playgroud)
和非常典型的简单控制器如下:
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
[HttpGet("{id}")]
public ActionResult<string> Get(int id)
{
return "value";
}
// POST api/values
[HttpPost]
public void Post([FromBody] string value)
{
}
// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] …Run Code Online (Sandbox Code Playgroud) https kestrel-http-server asp.net-core asp.net-core-webapi asp.net-core-2.0
I have developed various webservices in the past (VB ASP.net web-api applications) with https for production. I have done the development with http and then setup https on the production servers. To setup a port on the production server for https and the certificate, I have:
netsh http add urlacl url=https://+:22224/ user=everyone
https certificate asp.net-core-mvc kestrel-http-server asp.net-core-2.1
我一直在尝试 ASP.NET 的所有建议解决方法,以便能够通过 HTTP 方法 PUT 和 DELETE 解决我的 REST Web 服务。但是,它们似乎都不起作用。(即删除 WebDAV 处理程序或允许所有动词到 ExtensionlessHandler)。
ASP.NET Core Web API(在 IIS 上)需要什么来允许这两个动词(HTTP PUT 和 DELETE)?
PS:我已经使用 CORS 配置了我们的 Web API 项目,但我正在从同一来源的网页访问 Web 服务。所以这也不是 CORS 问题。
我无法让路由与 kestrel 一起工作。
我找不到关于如何在 netcore 控制台应用程序中实现这一点的任何好的教程。
我想构建一个简单的 Web 服务器,它将有 2-3 个我可以访问的端点。
public class WebServer
{
public static void Init()
{
IWebHostBuilder builder = CreateWebHostBuilder(null);
IWebHost host = builder.Build();
host.Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.Build();
return WebHost.CreateDefaultBuilder(args)
.UseUrls("http://*:5000")
.UseConfiguration(config)
.UseStartup<Startup>();
}
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddRouting();
// ????
}
public void Configure(IApplicationBuilder app)
{
// ????
}
}
}
Run Code Online (Sandbox Code Playgroud) asp.net-core ×7
c# ×4
.net-core ×2
https ×2
.net ×1
ascii ×1
asp.net ×1
certificate ×1
iis ×1
iis-7.5 ×1
kestrel ×1
logging ×1
middleware ×1
rest ×1