System.InvalidOperationException when I run the websit through IIS

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?

 
mazin_kfAsked:
Who is Participating?
 
DropZoneCommented:
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
 
SnowFlakeCommented:
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
 
DropZoneCommented:
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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
DropZoneCommented:
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
 
DropZoneCommented:
Sorry for the double post.

       -dZ.
0
 
mazin_kfAuthor Commented:
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
 
SnowFlakeCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.