?
Solved

System.InvalidOperationException when I run the websit through IIS

Posted on 2007-08-05
9
Medium Priority
?
2,584 Views
Last Modified: 2008-09-17
I am developing a small websit using ASP.NET it is working fine through visual studio 2005, but when I run it through IIS (V6.0) it gives me this error:

"Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application."

I think because I am using MessageBox.show(....);

So, how can I solve this problem?

 
0
Comment
Question by:mazin_kf
  • 4
  • 2
7 Comments
 
LVL 15

Expert Comment

by:SnowFlake
ID: 19633953
you are probably right,
are you running this on some special thread ? or as a service ?
if you know exactly where it happens then the way to handle it depends on your needs,
why are you showing this messagebox ? there is usually no point in doing so in a web app.
where do you expect/want the message to apear ? on the server ? on the client ?

SnowFlake
0
 
LVL 18

Expert Comment

by:DropZone
ID: 19633962
That is exactly right:  You cannot use MessageBox.show from server-side code.  Such code may work while debugging on your development machine, but once the application is deployed, the web server (IIS) will not have any access to the User Interface at all, and so you will need to look for other ways to interact with it.

What is it that you are trying to accomplish with it?  

If you are displaying messages for debugging purposes, then you can (and should) remove such code from your production code prior to deployment.  Alternatively, you may want to write to the EventLog, the Trace Log, or to your own log file using the Listeners Streams.

     -dZ.
0
 
LVL 18

Expert Comment

by:DropZone
ID: 19633966
That is exactly right:  You cannot use MessageBox.show from server-side code.  Such code may work while debugging on your development machine, but once the application is deployed, the web server (IIS) will not have any access to the User Interface at all, and so you will need to look for other ways to interact with it.

What is it that you are trying to accomplish with it?  

If you are displaying messages for debugging purposes, then you can (and should) remove such code from your production code prior to deployment.  Alternatively, you may want to write to the EventLog, the Trace Log, or to your own log file using the Listeners Streams.

     -dZ.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 18

Expert Comment

by:DropZone
ID: 19633970
Sorry for the double post.

       -dZ.
0
 

Author Comment

by:mazin_kf
ID: 19633988
Why am I using msgBox?
This page takes some text , and when the user click the submit button, the page will wite this text to XML file and display the msgBox telling that the process done successfully.

I need the msgBox to be displayed rather than using another page to tell that.

I heared some solution using Environment.UserInteractive property, but how can I use it and where?

Thank you;
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 19634135
hmmm...
If this is an alert that should be seen on the client side then the code should take care to render it as appropriate to a javasctip alert or some other client side manipulation of the code to show the alert.

anyway if you use Environment.UserInteractive  or enen a plain try catch block around your msgBox you will probably not get the error bu t you will still not get the message either.

is this page available online somewhere that we can see to give you better advice ?
0
 
LVL 18

Accepted Solution

by:
DropZone earned 2000 total points
ID: 19634197
What you are saying is that you want the message box to be displayed to the user.  In this case, you need it to be executed as client-side code.  Make sure that the control that has the MessageBox code does not have runat="server", or else it will try to execute it on the server-side.

You could do this easily by using the Page.RegisterStartupScript() method, which will take a block of client-side script and injected into the output stream, and make it execute as soon as the page loads.

It would be wise, in this regard, to use JavaScript (alert() function)instead of VBScript, to ensure that it runs on most browsers.  VBScript only works in Internet Explorer.

An example would be that at the end of your processing you add this code:

.....
    ' set this with the status msg of the process (success or failed)
    StrStatus = "Success!"

    ' generate javascript to pop-up a message box
    StrScript = "<script language=""javascript"" type=""text/javascript"">" & vbCrLf
    StrScript = StrScript & "alert('" & StrStatus & "');" & vbCrLf
    StrScript = StrScript & "</script>" & vbCrLf

    ' register the script to run at startup of the page
    Page.RegisterStartupScript('StatusMsg', StrScript);


    -dZ.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
A phishing scam that claims a recipient’s credit card details have been “suspended” is the latest trend in spoof emails.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question