让我们假设下面的代码,它允许您在不同的AppDomain中调用一个类并处理几乎所有异常:
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace MyAppDomain
{
class Program
{
static void Main(string[] args)
{
AppDomain myDomain = null;
try
{
myDomain = AppDomain.CreateDomain("Remote Domain");
myDomain.UnhandledException += new UnhandledExceptionEventHandler(myDomain_UnhandledException);
Worker remoteWorker = (Worker)myDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, typeof(Worker).FullName);
remoteWorker.VeryBadMethod();
}
catch(Exception ex)
{
myDomain_UnhandledException(myDomain, new UnhandledExceptionEventArgs(ex, false));
}
finally
{
if (myDomain != null)
AppDomain.Unload(myDomain);
}
Console.ReadLine();
}
static void myDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Exception ex = e.ExceptionObject as Exception;
if (ex != null)
Console.WriteLine(ex.Message);
else
Console.WriteLine("A unknown …Run Code Online (Sandbox Code Playgroud) 我以UTC格式从我的网络应用程序发送日期,但是当我在服务器端接收它们时,JSon序列化程序(可能通过设置模型使用)使用DateTimeKind.Local相对于本地日期和时间到服务器的时区.
当我做DateTime.ToUniversalTime()时,我得到了正确的UTC日期,所以这不是问题.转换工作正常,日期按照应该的方式发送......但是...... 我不喜欢在模型中的每个日期都调用'ToUniversalTime()',然后将其存储到数据库中...当你有一个大应用程序时,这容易出错并且容易忘记.
所以这里有一个问题:有没有办法告诉MVC传入日期应该始终以UTC格式表示?
有没有人已经尝试过这个,我需要注意哪些特殊情况?