我需要帮助来获取我的应用程序的主机/域名和端口。
到目前为止,这是我的Configure
方法中的示例代码Startup.cs
:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
var url = ""; // something that will get the current host/domain and port of the running applicaiton.
RecurringJob.AddOrUpdate<ISomething>(i=>i.SomethingToExecute(url), Cron.Daily);
}
Run Code Online (Sandbox Code Playgroud)
因为我需要将url
字符串传递给我的SomethingToExecute
方法
public class Something : ISomething
{
public void SomethingToExecute(string url){
...
Debug.WriteLine(url)
}
}
Run Code Online (Sandbox Code Playgroud) 大家好
我正在尝试从Axios Request从ASP.NET Core Web API下载文件。
这是我的示例API方法。(基于此stackoverflow问题的代码)
[HttpPost("download")]
public async Task<IActionResult> DownloadFile(){
...
return File(new MemoryStream(mypdfbyte), "application/octet-stream", "myfile.pdf");
}
Run Code Online (Sandbox Code Playgroud)
这是我的示例axios请求。
axios.post(`api/products/download`).then(response=>{
console.log(response.data)
}).catch(error=>{ console.log(error) })
Run Code Online (Sandbox Code Playgroud)
但是我只收到这个。没有下载文件出现。
希望您能帮助我从控制器api下载文件。
美好的一天,
我正在尝试检查令牌的到期日期是否已过期。我正在使用JWT生成令牌。通过使用此代码,我可以在我的JavaScript环境中检查我的令牌是否仍然有效。
if (decodedToken.exp < new Date().getTime() / 1000) {
alert("Session expired);
}
// decodedToken.exp returns a value like "1556797243"
Run Code Online (Sandbox Code Playgroud)
但是我的问题是,如果令牌已经过期,我不知道如何使用C#代码进行验证。
我尝试过这样的事情
// suppose I have a value of "1556797243"
var expirationDate = DateTime.ParseExact(expiration, "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)
但这是行不通的。