zoukankan      html  css  js  c++  java
  • 【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:STLasp_net_web_seniorasp_net_web_seniorPluginsSPMS.student_info_msDefault.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

     
  • 相关阅读:
    洛谷 P2695 骑士的工作
    洛谷 P2839 畅通工程
    hdu_5742_It's All In The Mind
    hdu_5734_Acperience
    hdu_5738_Eureka(脑洞)
    hdu_5724_Chess(组合博弈)
    Codeforces Round #363 (Div. 2)D. Fix a Tree(并查集)
    Codeforces Round #363 (Div. 2) B. One Bomb (水题)
    Codeforces Round #363 (Div. 2) C. Vacations(DP)
    hdu_5723_Abandoned country(最小生成树)
  • 原文地址:https://www.cnblogs.com/caoming/p/4138601.html
Copyright © 2011-2022 走看看