我有简单的 url 重写器:
private static void RedirectToAPI(RewriteContext context)
{
var request = context.HttpContext.Request;
if (request.Path.Value.StartsWith("/apiendpoint", StringComparison.OrdinalIgnoreCase))
{
var json = JsonConvert.SerializeObject(request.Path.Value
.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)
.Skip(1));
var response = context.HttpContext.Response;
response.Headers[HeaderNames.Location] = $"/custom";
response.StatusCode = StatusCodes.Status301MovedPermanently;
context.Result = RuleResult.EndResponse;
using (var bodyWriter = new StreamWriter(response.Body))
{
bodyWriter.Write(json);
bodyWriter.Flush();
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,当它重定向到/custom url 时,请求有方法 GET,而这个方法需要 POST。
比如发送 GET 请求到 url /apiendpoint/first/second/third,然后 rewriter 响应重定向,相应地,下面的请求必须是 POST 方法,但现在,它是 GET。
如何更改请求方法,即在 url 重写器响应之后?
我如何Name在Display属性中进行本地化?例如:
[Display(Name = "Library name")]
public string LibraryName { get; set; }
Run Code Online (Sandbox Code Playgroud)
该属性该怎么办?
这是我的web.config文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false">
<environmentVariables>
<environmentVariable name="TEST_WEBCONFIG_VARIABLE" value="some test webconfig variable value" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
如何TEST_WEBCONFIG_VARIABLE从我的web.config中读取Startup.cs?
我尝试过Configuration["TEST_WEBCONFIG_VARIABLE"],但配置值列表中不存在该变量。
我有我的类库,它由ViewRenderService类组成:
public interface IViewRenderService
{
Task<string> RenderToStringAsync(string viewName, object model);
}
public class ViewRenderService : IViewRenderService
{
private readonly IRazorViewEngine _razorViewEngine;
private readonly ITempDataProvider _tempDataProvider;
private readonly IServiceProvider _serviceProvider;
public ViewRenderService(IRazorViewEngine razorViewEngine,
ITempDataProvider tempDataProvider,
IServiceProvider serviceProvider)
{
_razorViewEngine = razorViewEngine;
_tempDataProvider = tempDataProvider;
_serviceProvider = serviceProvider;
}
public async Task<string> RenderToStringAsync(string viewName, object model)
{
var httpContext = new DefaultHttpContext { RequestServices = _serviceProvider };
var actionContext = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
using (var sw = …Run Code Online (Sandbox Code Playgroud) 我们来看看简单的类示例:
public class Book
{
[Key]
public string BookId { get; set; }
public List<BookPage> Pages { get; set; }
public string Text { get; set; }
}
public class BookPage
{
[Key]
public string BookPageId { get; set; }
public PageTitle PageTitle { get; set; }
public int Number { get; set; }
}
public class PageTitle
{
[Key]
public string PageTitleId { get; set; }
public string Title { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
所以,如果我想获得所有PageTitiles,如果我只知道BookId,我需要写一些包含,如下所示:
using (var dbContext = …Run Code Online (Sandbox Code Playgroud) 我从Visual Studio Web Application(Net.Core)模板创建了具有单个用户帐户授权的简单Web应用程序。
然后,我在中启用了SSL Project->MyProject Properties...,并使用https将URL复制到了App Url。
最后,我添加了:
services.AddMvc(options =>
{
options.Filters.Add(new RequireHttpsAttribute());
});
Run Code Online (Sandbox Code Playgroud)
到Startup。
而且它不起作用!当我启动该应用程序时,它只是在一秒钟后就关闭了,什么也没有发生,没有错误,什么也没有!
Asp.Net Core中的SSL有什么问题,如何正确启用它?
asp.net-core ×5
c# ×5
asp.net ×3
localization ×1
razor ×1
redirect ×1
ssl ×1
url ×1
web-config ×1