惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
美团技术团队
H
Hacker News: Front Page
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tenable Blog
Simon Willison's Weblog
Simon Willison's Weblog
T
The Exploit Database - CXSecurity.com
Cisco Talos Blog
Cisco Talos Blog
A
Arctic Wolf
C
CXSECURITY Database RSS Feed - CXSecurity.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
A
About on SuperTechFans
F
Fortinet All Blogs
量子位
GbyAI
GbyAI
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The Hacker News
The Hacker News
AWS News Blog
AWS News Blog
Forbes - Security
Forbes - Security
Help Net Security
Help Net Security
I
InfoQ
有赞技术团队
有赞技术团队
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
Engineering at Meta
Engineering at Meta
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
S
Secure Thoughts
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Webroot Blog
Webroot Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园_首页
C
Check Point Blog
T
Troy Hunt's Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Latest news
Latest news
P
Proofpoint News Feed
Jina AI
Jina AI
Last Week in AI
Last Week in AI
Martin Fowler
Martin Fowler
雷峰网
雷峰网
博客园 - Franky
L
LangChain Blog
罗磊的独立博客
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
D
Docker
G
GRAHAM CLULEY
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

博客园 - Franz

从如此简单的代码谈起 谈谈C#基元类型 TFS代码签入指导 并发之阿喀琉斯之踵 SmallDateTime时间范围检查 too many automatic redirections were attempted 预览Cube出现没有注册类错误 Transaction Manager Maximum Timeout .NET下的延迟加载 我的VisualStudio工具箱 简单的谈一下.NET下的AOP TFS上使用Beyond Compare来比较源码 SqlBulkCopy 是个好对象 释放Sql Server内存 书评《模式-工程化实现及扩展》 定义加载动画 代码共享的小技巧 WPF将控件保存为图片 《编程人生》的书评
吐槽一下Silverlight的SaveFileDialog.
Franz · 2013-02-22 · via 博客园 - Franz

2013-02-22 15:15  Franz  阅读(400)  评论()    收藏  举报

Silverlight为了安全是不允许你直接在非人为触发的环境下使用SaveFileDialog等对话框类.  必须在用户鼠标或者键盘事件的调用代码中才能够调用它的ShowDialog方法. 如果违反了就会出现"System.Security.SecurityException: 对话框必须由用户启动。"异常了.

这个条件其实是不充分的, 其实即便是是鼠标点击仍然还会出现这样的错误. 看一下这段代码

private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
	Thread.Sleep(1000);
	var saveDlg = new SaveFileDialog();
	saveDlg.Filter = "JPEG Files (*.jpeg)|*.jpeg";
	saveDlg.DefaultExt = ".jpeg";
	try
	{
		if ((bool)saveDlg.ShowDialog())
		{
		
		}
	}
	catch (Exception exception)
	{
		MessageBox.Show(exception.ToString());
	}
}

 这段代码时会恒定出错的, 移除Thread.Sleep(1000);是没有问题的.  这里说明了, 这个权限是有时限的, 如果从用户触发到调用ShowDialog不在1秒内那么就会报SecurityException.

这个不能算是个bug, 因为的确没有很好的方法来检查是用户触发的代码调用还是程序员自己写的代码调用.