简体   繁体   English

ASP.NET剃须刀是否在本地运行?

[英]Is ASP.NET razor run locally?

Currently I'm working on a global time localisation project, with a database stored as UTC I need to filter by date-time on the front-end 目前,我正在一个全球时间本地化项目中,数据库存储为UTC,我需要在前端按日期时间进行过滤

@{ foreach(var financialTransaction in Model.FinancialTransactionRows)
{
    //Do stuff
}

From my understanding of the DateTime class the time data is gathered from the local system. 据我对DateTime类的理解,时间数据是从本地系统收集的。 However, if I add the following Razor: 但是,如果我添加以下剃刀:

@{ foreach(var financialTransaction in Model.FinancialTransactionRows.Where(ft => ft.CreatedDateTime < DateTime.UtcNow.ToLocalTime())
 {
      //Do stuff
 }    

Is this going to be the local time in regards to the servers location or the users'? 这将是关于服务器位置或用户位置的本地时间吗?

Thanks. 谢谢。

Razor is typically part of the server-side processing, so it would be the server time. 剃刀通常是服务器端处理的一部分,因此它就是服务器时间。 You can use razor outside of a web-server though - so now I'm having images of razor hosted via blazor / web-assembly in a browser. 不过,您可以在网络服务器之外使用剃刀-因此,现在,我在浏览器中通过blazor / web-assembly托管了剃刀的图像。 That's a horrible image :) 这是一个可怕的形象:)

But: if you're just doing "normal things": this is strictly server-side. 但是:如果您只是在做“正常的事情”:严格来说这是服务器端的。 As a side note: you should usually hope that folks roughly agree on DateTime.UtcNow (barring a clock that is simply wrong); 附带说明:您通常应该希望人们大致同意DateTime.UtcNow (除非有一个完全错误的时钟); it is DateTime.Now that gets significantly different based on the locale. 现在是DateTime.Now ,根据语言环境而有很大不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM