码迷,mamicode.com
首页 > Windows程序 > 详细

【Exception—WebForm】当应用程序不是以 UserInteractive 模式运行时显示模式对话框或窗体是无效操作。请指定 ServiceNotification 或 DefaultDesktopOnly 样式,以显示服务应用程序发出的通知。

时间:2014-12-02 22:04:57      阅读:395      评论:0      收藏:0      [点我收藏+]

标签:des   style   io   ar   color   os   sp   for   strong   

  最近做的项目现在发布到服务器上开始测试了,本地好好的程序,到服务器上却报异常了:

  当应用程序不是以 UserInteractive 模式运行时显示模式对话框或窗体是无效操作。请指定 ServiceNotification 或 DefaultDesktopOnly 样式,以显示服务应用程序发出的通知。

 堆栈信息: 

[InvalidOperationException: 当应用程序不是以 UserInteractive 模式运行时显示模式对话框或窗体是无效操作。请指定 ServiceNotification 或 DefaultDesktopOnly 样式,以显示服务应用程序发出的通知。]
   System.Windows.Forms.MessageBox.ShowCore(IWin32Window owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, Boolean showHelp) +2880696
   SPMS.student_info_ms._Default.btnRead_Click(Object sender, EventArgs e) in f:\STL\asp_net_web_senior\asp_net_web_senior\Plugins\SPMS.student_info_ms\Default.aspx.cs:66
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9633962
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

可以看出问题出在MessageBox.Show()上,可以通过指定
当然你可以指定MessageBoxOptions.ServiceNotifcation来解决这个问题:
MessageBox.Show(msg, "Print Error", System.Windows.Forms.MessageBoxButtons.YesNo, 
   System.Windows.Forms.MessageBoxIcon.Error,     
   System.Windows.Forms.MessageBoxDefaultButton.Button1, 
   System.Windows.Forms.MessageBoxOptions.ServiceNotification);
但是如果你的项目部署在IIS上或者服务器托管的进程上没有任何桌面,上述方法并不能如你所愿。你可以通过后台写入js脚本来处理:
Response.Write(string.Fomate("<script>alert({0})</script>"),msg))

【Exception—WebForm】当应用程序不是以 UserInteractive 模式运行时显示模式对话框或窗体是无效操作。请指定 ServiceNotification 或 DefaultDesktopOnly 样式,以显示服务应用程序发出的通知。

标签:des   style   io   ar   color   os   sp   for   strong   

原文地址:http://www.cnblogs.com/caoming/p/4138601.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!