我正在尝试为在Win XP上运行的C++程序编写一个byteswap例程.我正在使用Visual Studio 2008编译.这就是我想出的:
int byteswap(int v) // This is good
{
return _byteswap_ulong(v);
}
double byteswap(double v) // This doesn't work for some values
{
union { // This trick is first used in Quake2 source I believe :D
__int64 i;
double d;
} conv;
conv.d = v;
conv.i = _byteswap_uint64(conv.i);
return conv.d;
}
Run Code Online (Sandbox Code Playgroud)
还有一个测试功能:
void testit() {
double a, b, c;
CString str;
for (a = -100; a < 100; a += 0.01) {
b = byteswap(a);
c …Run Code Online (Sandbox Code Playgroud) 想知道你对这个解决方案的看法,如果这是将错误信息传递给自定义页面的正确方法吗?
在web.config中:
<customErrors mode="On" defaultRedirect="~/Error.aspx"></customErrors>
Run Code Online (Sandbox Code Playgroud)
在Global.asax中:
<script RunAt="server">
void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
if (ex != null && Session != null)
{
ex.Data.Add("ErrorTime", DateTime.Now);
ex.Data.Add("ErrorSession", Session.SessionID);
HttpContext.Current.Cache["LastError"] = ex;
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
在我的Error.aspx.cs中:
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack) return;
if (HttpContext.Current.Cache["LastError"] != null)
{
Exception ex = (Exception)HttpContext.Current.Cache["LastError"];
if (ex.Data["ErrorTime"] != null && ex.Data["ErrorSession"] != null)
if ((DateTime)ex.Data["ErrorTime"] > DateTime.Now.AddSeconds(-30d) && ex.Data["ErrorSession"].ToString() == Session.SessionID)
Label1.Text = ex.InnerException.Message;
}
}
Run Code Online (Sandbox Code Playgroud)
问题:我不想从Global.asax做一个Server.Transfer因为..我不知道.对我来说似乎很笨拙.希望能够将customErrors更改为RemoteOnly.所以必须在某处保存最后一个异常,但不能是Session,所以保存到Cache但是有一些额外的数据(时间和SessionID),因为Cache是全局的,并且希望确保不向某人显示错误的错误.
我有点改变了我的代码.现在它只是: …