小编App*_*mmy的帖子

在Startup.cs的Configure中获取域名或主机名和端口

我需要帮助来获取我的应用程序的主机/域名和端口。

到目前为止,这是我的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)

c# asp.net asp.net-core asp.net-core-2.0 asp.net-core-2.1

6
推荐指数
1
解决办法
9107
查看次数

从Axios请求以ASP.NET Core API返回下载文件

大家好

我正在尝试从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下载文件。

c# asp.net-web-api asp.net-core axios

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

C#-从Int值获取日期

美好的一天,

我正在尝试检查令牌的到期日期是否已过期。我正在使用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)

但这是行不通的。

c# datetime jwt-auth

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