Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 12th, 2009, 04:13 PM
Registered User
 
Join Date: Feb 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Deployment Issue

Let me preface this post by saying that I skipped from chapter 11 to chapter 18 because I wanted to deploy my own tests and findings as I go along and possibly redo some of the chapters in the book so I may have missed something along the way. Let me also say that I am really impressed that VWD includes its own ftp transfer utility -- I had been using FileZilla for simple HTML pages in the past.

I have a domain and hosting services from GoDaddy with ASP.Net 2.0/3.5 enabled and the help there is not getting me where I need to be (though I haven't called them since I absolutely loathe the idea of talking on the phone for an hour). I made a simple site with a header, label with some text, a text box (txtPassWord), and a button (btnSubmit). Keep in mind that I have not looked at the chapter on Security so this is a half-hearted attempt at preventing unwanted users from entering the site.

I created a code behind file (VB) for the default.aspx page. It contains a simple conditional for the click event of btnSubmit which checks for an appropriate password (hardcoded into the logic at this point) and sends a msgBox (I am assuming this runs on the client side) if an incorrect password or nothing is entered into txtPassWord. Pretty straightforward, but I can provide the code if need be. The page works fine on my local machine.

I sent the files to the server at GoDaddy via ftp (using your Try It Out -- Using The Copy Web Site Option in the Copying Your Website section of chapter 18 -- no page number since I use Books 24/7). It is similar to copying to the File System and pretty self explanatory. Everything connected fine and the files were transferred without a hitch.

The HTML rendered fine in a browser (Firefox and IE7), but when I click btnSubmit I get the following error in FireFox:

Quote:
Server Error in '/inspire' Application.

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.

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

<%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.
Stack Trace:

[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.]
System.Windows.Forms.MessageBox.ShowCore(IWin32Win dow owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, Boolean showHelp) +1799842
System.Windows.Forms.MessageBox.Show(IWin32Window owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options) +26
Microsoft.VisualBasic.Interaction.MsgBox(Object Prompt, MsgBoxStyle Buttons, Object Title) +544
_Default.btnSubmit_Click(Object sender, EventArgs e) +60
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
So I went into the web.config file to fix the problem and found the following entry:

Code:
<compilation debug="false" strict="false" explicit="true">
This is default code added into the file and I really have no idea what it does other than perhaps showing the stack trace. I am familiar with using Option Explicit in my VBA code, but I don't know if that is relevant to this directive.

One other thing to point out (I don't know if it even makes a difference) is that this is being deployed to a subdomain I created with my GoDaddy hosting account.

So I guess my questions are:
  1. What is the purpose of the compilation directive I have shown above other than showing a stack trace in the browser upon throwing an error?
  2. What settings should I use and where should I place them (I would guess in the web.config file between the <system.web> tags) in order to enable objects like a Message Box on the client side (I assume that is where it is processed).
  3. Should I avoid using Message Boxes completely?
I am sorry about the lengthy post, but I am hoping it also might help someone else out and, for selfish reasons, will serve as a reference for me in the future. I wanted to include as much detail as possible.
Reply With Quote
  #2 (permalink)  
Old February 12th, 2009, 04:56 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Are you using something like:

MessageBox.Show("Some text");

If so, this will never work. MessageBox.Show is not a browser thing; it's a desktop / WinForms thing. If it did work, a message box would pop up on the *server* and not the client so you would need to go over to GoDaddy's and click OK on all of the open message boxes.... ;-)

Instead, use JavaScript's alert function. Place a Literal on a page and then in Code Behind do something like this:

myLiteral.Text = "<script>alert('Hello World');</script>";

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old February 12th, 2009, 05:19 PM
Registered User
 
Join Date: Feb 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am used to developing in MS Access and it seems I am not alone in assuming I can use a Message Box in the same way as my desktop applications. After googling my error from the above post, I found that one should avoid using it in production environments. The following link provided invaluable information:

http://www.beansoftware.com/ASP.NET-...ssage-Box.aspx

Using some of their code I adjusted my Default.aspx.vb file to the following:
Code:
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim strMessage As String = ""

        If Me.txtPassword.Text = "" Then
            strMessage = "No password entered.  Please enter the correct password"
            DisplayAlert(strMessage)
        ElseIf Me.txtPassword.Text <> "CorrectPassword" Then
            strMessage = "Incorrect password entered.  Please enter the correct password (case sensitive)"
            DisplayAlert(strMessage)
        Else
            'Direct to appropriate Start Page
        End If
    End Sub
    Private Sub DisplayAlert(ByVal strMsg As String)
        Dim strScript As String = "<script language=Javascript>"
        strScript += "alert(""" & strMsg & """);</script>"
        If (Not ClientScript.IsStartupScriptRegistered("clientScript")) Then
            ClientScript.RegisterClientScriptBlock(Me.GetType(), "clientScript", strScript)
        End If
    End Sub
End Class
It works! This is the part I love about the profession -- the simplest of overcome challenges feels so rewarding. Since I don't understand every bit of the JavaScript code, I still have some research to do (I hate not knowing what all of my code does) Any comments or suggestions are still GREATLY appreciated. I really hope this helps someone else out.

P.S.: I went back to FileZilla for transfers. It seems much quicker than the built in utility.
Reply With Quote
  #4 (permalink)  
Old February 12th, 2009, 07:14 PM
Registered User
 
Join Date: Feb 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yeah, so I have a new problem with the code I am using. For some reason, after I enter the correct password (which performs as it should by opening the new page), then navigate back using the browser's Back button, the script fires from DisplayAlert() before the page is rendered in the browser as though an incorrect password was supplied. When I click the OK button on the alert window, the page is displayed with the correct password in txtPassword. This makes no sense to me since the code should only be fired when btnSubmit is clicked.
Reply With Quote
  #5 (permalink)  
Old February 13th, 2009, 06:52 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
I found that one should avoid using it in production environments.
I don't think that's worded strong enough. I cannot be used at all; it may work on your develop machine but that's about it.
Quote:
This makes no sense to me since the code should only be fired when btnSubmit is clicked.
You have to be aware of the differences between server side and client side. The btnSubmit fires at the server and then sends HTML and JavaScript to the client where the code is parsed and the JavaScript is executed. So, the end result of the btnSubmit action and the entire page is an HTML document in the browser. When you click back in the browser you are seeing that same document again without another call to the server.

There are a few ways around this. First, make sure your pages are not cached. Clicking the back button will cause a reload of the page. This will give you some ideas: http://www.google.com/search?hl=en&q...asp.net+expire but basically it comes down to setting things like ExpiresAbsolute , Expires and CacheControl.

It may be better though to not use an alert box for this. It's common to just display a message above or below the login controls. That's what the asp:Login control does by default. You may want to check out the chapter on security to see how this works.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server2000 Desktop Edition deployment issue RajaWaqas C# 2005 1 July 15th, 2008 03:37 AM
Deployment Issue REPicurus Access 1 May 28th, 2008 02:21 AM
Deployment Issue sbv002 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 November 20th, 2007 03:56 PM
Deployment issue - TypeInitializationException eelisMX Pro VB.NET 2002/2003 0 March 31st, 2005 04:54 AM
deployment issue p_gauri7 Crystal Reports 0 January 19th, 2005 11:32 PM



All times are GMT -4. The time now is 11:38 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.