因此,随着ASP.NET Core 2.1的出现,Kestrel现在会自动在HTTP端创建一个HTTPS端点,并且默认项目模板设置为从HTTP重定向到HTTPS(这很容易撤消).
但是我的问题是......如何为我的项目完全禁用HTTPS.我已经阅读了文档,并使用了各种HTTPS配置设置,但我做的任何事情似乎都不允许我将其关闭并只运行HTTP项目.
我疯了还是只是错过了什么.我希望这很容易做到.
我设置了各种C#代码样式规则来生成错误,虽然违规在IDE中显示为错误(错误列表和文本编辑器中),但实际构建仍然成功.
谁能证实这一点?我在社区(家庭)和企业(工作)版本的VisualStudio/15.0.0 + 26228.9上进行了测试.由于代码样式违规,我无法获得任何构建.
我甚至尝试使用.editorconfig,并且构建仍然经历...
我有一个并排的Web API 2.2 APIController和OData v4 ODataController.我的APIController在内部使用路由属性(没有预定义的路由默认值):
[RoutePrefix("api")]
public class MyController : ApiController
{
[HttpGet]
[Route("My")]
public IHttpActionResult Get()
{
//Code Here
}
[HttpGet]
[Route("My")]
public IHttpActionResult Get([FromUri] String mykey)
{
//Code Here
}
}
Run Code Online (Sandbox Code Playgroud)
因此通过./api/My和./api/My/?mykey=value路由到
我已经尝试设置我的ODataController跟随类似的西装:
[ODataRoutePrefix("My")]
public class oMyController : ODataController {
[HttpGet]
public IHttpActionResult Get(ODataQueryOptions<FileModel> queryOptions) {
//Code Here
}
[HttpGet]
[ODataRoute("({mykey})")]
public IHttpActionResult Get([FromODataUri] String mykey) {
//Code Here
}
}
Run Code Online (Sandbox Code Playgroud)
像这样提前定义odata路线:
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<MyModel>("My");
config.MapODataServiceRoute(
routeName: "ODataRoute",
routePrefix: "odata",
model: builder.GetEdmModel()
);
Run Code Online (Sandbox Code Playgroud)
但尝试访问./odata/My和./odata/My(value)最终进入我的APIController而不是ODataController. …
我目前正在开发一个使用WCF实现REST API的企业Web应用程序.它采用的VirtualPathProvider赶上请求*.SVC文件(实际上并不存在),然后建立他们的飞行动态加载相关的WCF服务.这允许系统具有可以在运行时添加到应用程序的"模块",而不会影响Web服务器或使用它的任何人.
我想知道的是,如果在概念上可以使用Web API 2.我一直在做一些研究,但看起来路由只能在启动时配置...我希望的是一种手段处理为不存在的路线,并且基本上使用控制器名称从请求到查找和装载相关联的组件(如果存在),而编程添加新路由.
我刚开始使用Web API 2,所以我希望有一些更有经验的用户可以加入.基本上我的团队有兴趣转换到Web API 2以减少我们遇到的WCF的开销和复杂性,但这个特殊要求可能是一个交易破坏者.
asp.net-web-api asp.net-web-api-routing programmatically-created
Configuring Serilog using a JSON config, it is possible to configure log level switches as such:
"LevelSwitches": {
"$appLogLevel": "Debug",
"$netLogLevel": "Information",
"$sysLogLevel": "Error"
},
"MinimumLevel": {
"ControlledBy": "$appLogLevel",
"Override": {
"Microsoft": "$netLogLevel",
"System": "$sysLogLevel"
}
}
Run Code Online (Sandbox Code Playgroud)
the purpose of the switches (when instantiated in code) is to be accessed at a later time in order to change the minimum log levels during run-time. However when configured via the JSON config, I can't find a way to access those switch …
有没有一种简单的方法可以从OwinContext.Request实例解析多部分/表单数据信息 ?
我知道如何使用HttpContext.Current.Request.Form.Get()做到这一点,但是我不确定我是否真的想在Owin管道中做到这一点。
我知道我可以使用.ReadFormAsync()来获取IFormCollection,它对于标准提交似乎很好用,但是使用多部分/表单数据后,边界值,内容类型和变量名都被放入了键。因此,我不能只是执行formVars.Get(“ VariableName”),因为它不是变量名,而是一个复合值。似乎它不应该那样做...对吗?
public AppFunc PreAuthMiddleware(AppFunc next) {
AppFunc appFunc = async (IDictionary<string, object> environment) => {
IOwinContext context = new OwinContext(environment);
IFormCollection formVars = await context.Request.ReadFormAsync();
... Now What ...
await next.Invoke(environment);
};
return appFunc;
}
Run Code Online (Sandbox Code Playgroud)
我希望访问表单变量和文件数据就像使用HttpContext一样容易,但是似乎还有很多工作要做。
如果有人对此有任何见解,请告诉我。否则,如果我看到主要的内容类型是multi-part / form-data,那么我可能最终只会一起破解密钥名称。
给定 Base64 字符串,以下示例类将使用Newtonsoft.Json正确反序列化,但不能使用System.Text.Json:
using System;
using System.Text.Json.Serialization;
public class AvatarImage{
public Byte[] Data { get; set; } = null;
public AvatarImage() {
}
[JsonConstructor]
public AvatarImage(String Data) {
//Remove Base64 header info, leaving only the data block and convert it to a Byte array
this.Data = Convert.FromBase64String(Data.Remove(0, Data.IndexOf(',') + 1));
}
}
Run Code Online (Sandbox Code Playgroud)
对于 System.Text.Json,会引发以下异常:
must bind to an object property or field on deserialization. Each parameter name must match with a property or field on the …Run Code Online (Sandbox Code Playgroud) 我已经设置了一个Web API 2.2 ODataController,这样我就可以手动处理我的OData选项(即没有[EnableQuery]和/或使用ODataQueryOptions参数).但是我遇到了一个看起来像个bug的东西.给出以下代码:
public IHttpActionResult GetEmployees() {
//Get Queryable Item (in this case just an in-memory List made queryable)
IQueryable<Employee> employees = _Employees.AsQueryable();
//Get Requested URI without querystring (there may be other ways of doing this)
String newUri = Request.RequestUri.AbsoluteUri;
if (!String.IsNullOrEmpty(Request.RequestUri.Query)) {
newUri = newUri.Replace(Request.RequestUri.Query, "");
}
//Add custom OData querystring (this is for example purposes)
newUri = String.Format("{0}?$skip={1}&$top={2}", newUri, 1, 1);
//Create new HttpRequestMessage from the updated URI
HttpRequestMessage newRequest = new HttpRequestMessage(Request.Method, newUri);
//Create new ODataQueryContext …Run Code Online (Sandbox Code Playgroud) 我正在创建 VSCode 扩展来为现有 Lua API 进行代码补全。
我在实现以下目标时遇到了一些麻烦(示例是 JavaScript):
我一直在寻找示例和教程,但没有找到太多。我假设我可能需要在当前光标位置周围进行大量的字符串处理,以获得足够的数据来查找适当的文档(我将其存储在 json 对象数组中)。但目前我不知道如何在输入参数时显示元数据对话框。
PS 我已经查看了官方扩展示例。
我目前正在使用 ASP.NET Core 2.2 进行开发:
dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.2.300
Commit: 73efd5bd87
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.2.300\
Run Code Online (Sandbox Code Playgroud)
并运行:
dotnet myapp.dll --environment=Local
Run Code Online (Sandbox Code Playgroud)
会将我的 IHostingEnvironment 设置为“Local”,但我找不到任何关于 --environment 的官方文档以及它是否会覆盖 ASPNETCORE_ENVIRONMENT 环境变量(看起来似乎不会)。
在构建配置、设置日志记录等时,我特别需要在 Program.cs 中使用此参数,并且不希望在系统范围内使用 ASPNETCORE_ENVIRONMENT。
但看来在 Program.cs 中,我需要手动读取参数(以及处理其缺失的情况),因为 IHostingEnvironment 直到稍后才设置,并且 Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") 显然将为 NULL。
当然,我仍然需要处理 ASPNETCORE_ENVIRONMENT 是否已设置,并适当选择要使用的,这就是为什么我需要知道框架的其余部分如何处理 --environment 参数。所以我可以效仿。
我知道我需要使用Restrictions.Eq和Projections.SqlFunction,但我已经尝试了几个小时没有任何成功(我的测试应用程序只是崩溃).有没有人有一个QueryOver示例,可以在Oracle中执行以下操作:
SELECT
*
FROM
V_LOG_ENTRIES
WHERE
regexp_like(ENTRY_TEXT, '(\WPlaced\W)');
Run Code Online (Sandbox Code Playgroud)
更新:好的,我认为部分问题是Restrictions.Eq期望相等,但在这种情况下没有相等,它只是WHERE子句中的函数调用...
odata ×2
odata-v4 ×2
.net ×1
.net-5 ×1
c# ×1
command-line ×1
constructor ×1
editorconfig ×1
environment ×1
forms ×1
function ×1
https ×1
json ×1
msbuild ×1
nhibernate ×1
owin ×1
queryover ×1
regex ×1
serilog ×1
sql ×1