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

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

  

当应用程序不是以 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))

 转载请注明来源:http://www.cnblogs.com/caoming/p/4138601.html

 
posted @ 2014-12-02 21:46  Norton.Li  阅读(2672)  评论(0编辑  收藏  举报