www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 27

Thread: asp.net error page

  1. #1
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,224

    asp.net error page

    How whould I go about making an error page for asp.net? You know like a 404 error page those cool ones except one for asp.net when I get an error in one of my applications?

  2. #2
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    hi,
    within your Web.Config file you need to add this code:

    Code:
    <configuration>
        <system.web>
                <customErrors mode="On" defaultRedirect="AppError.aspx">
                      <error statusCode="404" redirect="NotFound.aspx" /> 
                      <error statusCode="500" redirect="AppError.aspx" /> 
        </system.web>
    </configuration>
    Hope this helps.
    ----------------------------------

  3. #3
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,224
    Thanks! What are my "server error in '/' applications"'s 500? Hey do you have aim or msn messanger?

  4. #4
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,224
    web.config file, what the heck is that?

  5. #5
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    hi,
    a 500 is usually a error during compiling, just means there is an error in your code.
    The web.config if is new to ASP.NET. It allows you to make server configuration without needing the host to do anything. It normal sits in root with your global.asax file which is the ASP.NET eqivilant to the ASP global.asa file. The web.config file is written in XML and can look like this:

    Code:
    <configuration>
    <system.web>
    <compilation defaultLanguage="vb" debug="true" />
    
    <customErrors mode="RemoteOnly" />
    
    <trace enabled="false"
    requestLimit="10"
    pageOutput="false"
    traceMode="SortByTime"
    localOnly="true" />
    
    <sessionState mode="InProc"
    	cookieless="false"
    timeout="20" />
    <globalization requestEncoding="utf-8"
    	responseEncoding="utf-8" />
    </system.web>
    <appSettings>
    	<add key="appName" value="DBWeb" />
    	<add key="appAuthor" value="David Bell BA" />
    </appSettings>
    </configuration>
    ----------------------------------

  6. #6
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,224
    AHHH NOT A GLOBAL.ASAX , my host is a nazi and wont let me use one. Is there an alternative to a an asax? Any other place I can pu the thing? Is my view state a 500 error? Also whats wrong with that code that is making it do that error?

  7. #7
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    hi,
    i can't think of any reason why your host would not let you use a global.asa file. Anyway you add custom errors to the web.config file and not global.asax file.
    Is my view state a 500 error?
    Yes, your error is caused by incorrect syntax in your web and validation controls. You have the following code in your page:

    Code:
    <asp:RequiredFieldValidator
        id="rfvMemberName"
        ControlToValidate="txtMemberName"
        Display="Dynamic"
        Font-Name="Tahoma"
        Font-Size="10pt"
        runat=server>
        Member Name is Required!
    </asp:RequiredFieldValidator>
    This is incorrect syntax in your control. The correct syntax is this:

    Code:
    <asp:RequiredFieldValidator 
    ControlToValidate="txtMemberName"
    Display="Dynamic" 
    Font-Name="Tahoma"
    Font-Size="10pt" 
    id="rfvMemberName"
    runat="server" 
    ErrorMessage="Member Name is Required!"
    >
    </asp:RequiredFieldValidator>
    Once you fix these errors you'll need to work on correct syntax for creating SQL querries using parameters.
    ----------------------------------

  8. #8
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,224
    Well my host wont let me put any objects into anything application level or something like that. It is a free account and all and they stomp on us people that dont like to pay for practice sites. They are real strict about loops too.
    The runat="server" alone did not work. I will try putting that "that feild if required" in an error message like you have it. The sql, what is wrong with that, that you have seen so far? The forum I might just ditch because it has some other problems that will be hard to fix but I am having view state errors on another project I am working on. I might try a forum again later but I whould use a different design. I like my drop down label though because it stream lines things but it limits the forums functionality. Thanks for your help so far Ill try to fix the errors on my other pages.

    Code:
    <%@ Page Language=VB Debug=true %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.OLEDB" %>
    <script runat="server">
    Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
        if txtrank.selecteditem.value = "Peasent" then
        lblrnkval.text="1"
        end if
        if txtrank.selecteditem.value = "Soldier" then
        lblrnkval.text="2"
        end if
        if txtrank.selecteditem.value = "Page" then
        lblrnkval.text="3"
        end if
        if txtrank.selecteditem.value = "Guard" then
        lblrnkval.text="4"
        end if
        if txtrank.selecteditem.value = "Knight" then
        lblrnkval.text="5"
        end if
        if txtrank.selecteditem.value = "Elite" then
        lblrnkval.text="6"
        end if
        if txtrank.selecteditem.value = "Lord" then
        lblrnkval.text="7"
        end if
        if txtrank.selecteditem.value = "Preist" then
        lblrnkval.text="8"
        end if
        if txtrank.selecteditem.value = "Paladin" then
        lblrnkval.text="9"
        end if
        if txtrank.selecteditem.value = "Apprentice" then
        lblrnkval.text="10"
        end if
        if txtrank.selecteditem.value = "Noble" then
        lblrnkval.text="11"
        end if
    
    
        Dim DBConn as OleDbConnection
        Dim DBCommand As OleDbDataAdapter
        Dim DSLogin as New DataSet
        Dim DBInsert As New OleDbCommand
        DBConn = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
            & "DATA SOURCE=" _
            & Server.MapPath("/knightsempire/db/members/" _
            & "members.mdb;"))
        DBCommand = New OleDbDataAdapter _
            ("Select Count(MemberID) as TheCount " _
            & "from Members Where " _
            & "MemName = '" & txtMemberName.Text _
            & "'", DBConn) 
        DBCommand.Fill(DSLogin, _
            "TheCount")
        If DSLogin.Tables("TheCount").Rows(0).Item("TheCount")  = 0 Then
            DBInsert.CommandText = "Insert Into Members " _
                & "(MemName, [Password],bots, rank, rankval, sc, d2, wc3, Email) " _
                & "values (" _
                & "'" & Replace(txtMemberName.text, "'", "''") & "', " _
                & "'" & Replace(txtPassword.text, "'", "''") & "', " _
                & "'" & Replace(txtbots.text, "'", "''") & "', " _
                & "'" & Replace(txtrank.selecteditem.value, "'", "''") & "', " _
                & "'" & Replace(lblrnkval.text, "'", "''") & "', " _
                & "'" & Replace(ddlsc.selecteditem.value, "'", "''") & "', " _
                & "'" & Replace(ddld2.selecteditem.value, "'", "''") & "', " _
                & "'" & Replace(ddlwc3.selecteditem.value, "'", "''") & "', " _
                & "'" & Replace(txtEmailAddress.text, "'", "''") & "')"
            DBInsert.Connection = DBConn
            DBInsert.Connection.Open
            DBInsert.ExecuteNonQuery()
            DBCommand = New OleDbDataAdapter _
                ("Select MemberID from Members Where " _
                & "MemberName = '" & txtMemberName.Text _
                & "' and Password = '" & txtPassword.Text _
                & "'", DBConn) 
           
            Response.Redirect("./list.aspx")	
    	 Else
    	     lblMessage.Text = "The member name you entered is in " _
    	         & "use by another member. Please enter " _
    	         & "another member name."
    	 End If
    End Sub
    </SCRIPT>
    <HTML>
    <HEAD>
    <TITLE>Register</TITLE>
    </HEAD>
    <BODY BACKGROUND="http://www12.brinkster.com/knightsempire/tilehdark.jpg" TEXT="4682b4" LINK="00ffff" VLINK="00ffff" ALINK="00ffff" LEFTMARGIN="40">
    <!--
       function MM_openBrWindow(theURL,winName,features) { //v2.0
         window.open(theURL,winName,features);
       }
       //-->
       </script>
       
       <style>
       
       body {
       
       scrollbar-arrow-color:#003366;
       
       scrollbar-track-color:#000000;
       
       scrollbar-shadow-color:#003366;
       
       scrollbar-face-color:#000000;
       
       scrollbar-highlight-color:#003366;
       
       scrollbar-darkshadow-color:#000000;
       
       scrollbar-3dlight-color:#000000;
       
       }
       
       </style>
    <table bgcolor="000000" align="center" cellpadding="10" style="border: 1px solid #003366">
    <tr>
    <td>
    <form runat="server">
    <CENTER>
    <asp:Label 
        id="lblTitle" 
        BorderWidth="0px"
        BorderStyle=7
           Width="90%"
        Font-Size="15pt"
        Font-Name="Ms Sans Serif"
        Text="New Recruits"
        runat="server"
    />
    </CENTER>
    
    <P></P>
    <asp:Label 
        id="lblMessage" 
        Font-Size="12pt"
        Font-Name="Tahoma"
        runat="server"
        Text="Complete each field to add your account to the data base."
    />
    <P></P><Font Face="Tahoma">Member Name:</Font><BR>
    <style type="text/css"> 
    </style> 
    <asp:TextBox 
        id="txtMemberName" 
        Columns="25"
        MaxLength="30"
        runat="server" 
        />
    <P></P><Font Face="Tahoma">Password:</Font><BR>
    <asp:TextBox 
        id="txtPassword" 
        Columns="25"
        MaxLength="30"
        runat="server" 
        TextMode="Password"
    />
    <asp:RequiredFieldValidator 
        id="rfvPassword"
        ControlToValidate="txtPassword"
        Display="Dynamic"
        Font-Name="Tahoma"
        Font-Size="10pt"
        runat="server">
        Password is Required!
    </asp:RequiredFieldValidator>
    <P></P><Font Face="Tahoma">Repeat Password:</Font><BR>
    <asp:TextBox 
        id="txtPassword2" 
        Columns="25"
        MaxLength="30"
        runat=server 
        TextMode="Password"
    />
    <asp:RequiredFieldValidator 
        id="rfvPassword2"
        ControlToValidate="txtPassword2"
        Display="Dynamic"
        Font-Name="Tahoma"
        Font-Size="10pt"
        runat="server">
        Password is Required!
    </asp:RequiredFieldValidator>
    <asp:CompareValidator id="cvPassword"
        ControlToValidate="txtPassword" 
        ControlToCompare="txtPassword2"
        Display="Dynamic"
        Font-Name="Tahoma"
        Font-Size="10pt"
        runat=server>
        Password fields don't match
    </asp:CompareValidator>
    
    <P></P><Font Face="Tahoma">Your Rank:</Font><BR>
    <asp:dropdownlist
     id="txtrank"
     runat="server">
     <asp:ListItem value="Peasent">Peasent</asp:listitem>
     <asp:ListItem value="Soldier">Soldier</asp:listitem>
     <asp:ListItem value="Page">Page</asp:listitem>
     <asp:ListItem value="Guard">Guard</asp:listitem>
     <asp:ListItem value="Knight">Knight</asp:listitem>
     <asp:ListItem value="Elite">Elite</asp:listitem>
     <asp:ListItem value="Lord">Lord</asp:listitem>
     <asp:ListItem value="Preist">Preist</asp:listitem>
     <asp:ListItem value="Paladin">Paladin</asp:listitem>
     <asp:ListItem value="Apprentice">Apprentice</asp:listitem>
     <asp:ListItem value="Noble">Noble</asp:listitem>
    </asp:dropdownlist>
    
    
    <asp:Label 
        id="lblrnkval" 
        Font-Size="12pt"
        Font-Name="Tahoma"
        runat="server"
        Text="1"
        visible="false"
    />
    <asp:RequiredFieldValidator 
        id="rfvMemberName"
        ControlToValidate="txtMemberName"
        Display="Dynamic"
        Font-Name="Tahoma"
        Font-Size="10pt"
        runat="server">
        Member Name is Required!
    </asp:RequiredFieldValidator>
    <P></P><Font Face="Tahoma">Do you load bots, if so how many:</Font><BR>
    <asp:TextBox 
        id="txtbots" 
        Columns="25"
        MaxLength="30"
        runat="server" 
        text="0"
        />
    <P></P><Font Face="Tahoma">Email Address:</Font><BR>
    <asp:TextBox 
        id="txtEmailAddress" 
        Columns="25"
        MaxLength="30"
        runat="server" 
    />
    <asp:RequiredFieldValidator 
        id="rfvEmailAddress"
        ControlToValidate="txtEmailAddress"
        Display="Dynamic"
        Font-Name="Tahoma"
        Font-Size="10pt"
        runat="server">
        Email Address is Required!
    </asp:RequiredFieldValidator>
    <BR><BR>
    <P></P><Font Face="Tahoma">Do you play Diablo2/Diablo2 x?:</Font><BR>
    <asp:dropdownlist
     id="ddld2"
     runat="server">
     <asp:ListItem value="-">No</asp:listitem>
     <asp:ListItem value="<li>">Yes</asp:listitem>
    </asp:dropdownlist>
    <P></P><Font Face="Tahoma">Do you play StarCraft/Brood War?:</Font><BR>
    <asp:dropdownlist
     id="ddlsc"
     runat="server">
     <asp:ListItem value="-">No</asp:listitem>
     <asp:ListItem value="<li>">Yes</asp:listitem>
    </asp:dropdownlist>
    <P></P><Font Face="Tahoma">Do you play Warcraft3?:</Font><BR>
    <asp:dropdownlist
     id="ddlwc3"
     runat="server">
     <asp:ListItem value="-">No</asp:listitem>
     <asp:ListItem value="<li>">Yes</asp:listitem>
    </asp:dropdownlist>
    <br><br>
    <asp:button 
        id="butOK"
        text="  OK  "
        Type="Submit"
        OnClick="SubmitBtn_Click" 
        runat="server"
    />
    <br><br>If you encounter any errors in this application please use this <a href="http://www12.brinkster.com/knightsempire/submit.html">Link</a>
    </td>
    </tr>
    </table>
    </Form>
    </BODY>
    </HTML>
    Thats what I have so far for this new sign up sheet incase you are interested.

  9. #9
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,224
    That should be all the code I need but I have view state errors on it

  10. #10
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    hi,
    if the above code is the new code then you haven't sorted out the ErrorMessage syntax yet:

    Code:
    <asp:RequiredFieldValidator 
    ControlToValidate="txtMemberName"
    Display="Dynamic" 
    Font-Name="Tahoma"
    Font-Size="10pt" 
    id="rfvMemberName"
    runat="server" >
        Member Name is Required!
    </asp:RequiredFieldValidator>
    The text in bold is wrong. Its wrong for this control and for about 4 others on the page. You need to change it to this:

    Code:
    <asp:RequiredFieldValidator 
    ControlToValidate="txtMemberName"
    Display="Dynamic" 
    Font-Name="Tahoma"
    Font-Size="10pt" 
    id="rfvMemberName"
    runat="server" 
    ErrorMessage="Member Name is Required!"
    >
    </asp:RequiredFieldValidator>
    This is what is causing your error. You need to fix this before moving on to your next error.

    I would also like to point out that you have added a lot of new code since the last time i seen your code. Surely its better to fix your errors first before adding more code.
    You're SQL statement should like something like the following code.
    Code:
    		Dim CmdStr As String
    
           CmdStr = "Insert Into Members " _
                & "(MemberName, [Password], EmailAddress) " _
                & "values (@MemberName, @Password, @EmailAddress)" 
    
    			 DBInsert  = new OleDbCommand(CmdStr, DBconn)
    			 DBInsert.Parameters.Add("@MemberName", OleDbType.VarChar, 255)
    			 DBInsert.Parameters.Add("@Password", OleDbType.VarChar, 255)
    			 DBInsert.Parameters.Add("@EmailAddress",  OleDbType.VarChar, 255)
            	
    			 DBInsert.Parameters("@MemberName").Value = Replace(txtMemberName.text, "'", "''")
    			 DBInsert.Parameters("@Password").Value = Replace(txtPassword.text, "'", "''")
    			 DBInsert.Parameters("@EmailAddress").Value = Replace(txtEmailAddress.text, "'", "''")
    		DBConn.Open()
    		 DBInsert.ExecuteNonQuery()
    Fix some of these errors then we can take it from there.
    ----------------------------------

  11. #11
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,224
    Thanks!
    Code:
     Dim CmdStr As String
            CmdStr = "Insert Into Members " _
                & "(MemName, [Password],bots, rank, rankval, sc, d2, wc3, Email) " _
                & "values (@memname, @password, @bots, @rank, @rankval, @sc, @d2, @wc3, @email)" 
               
                   DBInsert  = new OleDbCommand(CmdStr, DBconn)
    			 DBInsert.Parameters.Add("@memname", OleDbType.VarChar, 255)
    			 DBInsert.Parameters.Add("@password", OleDbType.VarChar, 255)
    			 DBInsert.Parameters.Add("@bots", OleDbType.VarChar, 255)
    			 DBInsert.Parameters.Add("@rank", OleDbType.VarChar, 255)
    			 DBInsert.Parameters.Add("@rankval",  OleDbType.VarChar, 255)
                             DBInsert.Parameters.Add("@sc", OleDbType.VarChar, 255)
    			 DBInsert.Parameters.Add("@d2", OleDbType.VarChar, 255)
    			 DBInsert.Parameters.Add("@wc3",  OleDbType.VarChar, 255)
                             DBInsert.Parameters.Add("@email",  OleDbType.VarChar, 255)
    
                             
    
    			 DBInsert.Parameters("@memname").Value = Replace(txtMemberName.text, "'", "''")
    			 DBInsert.Parameters("@password").Value = Replace(txtPassword.text, "'", "''")
    			 DBInsert.Parameters("@bots").Value = Replace(txtbots.text, "'", "''")
    			 DBInsert.Parameters("@rank").Value = Replace(txtrank.selecteditem.value, "'", "''")
    			 DBInsert.Parameters("@rankval").Value = Replace(lblrnkval.text, "'", "''") 
                             DBInsert.Parameters("@sc").Value = Replace(ddlsc.selecteditem.value, "'", "''")
    			 DBInsert.Parameters("@d2").Value = Replace(ddld2.selecteditem.value, "'", "''")
    			 DBInsert.Parameters("@wc3").Value = Replace(ddlwc3.selecteditem.value, "'", "''")
                             DBInsert.Parameters("@email").Value = Replace(txtEmailAddress.text, "'", "''")
    
    		DBConn.Open()
    		 DBInsert.ExecuteNonQuery()
    This is my new sql statement. Like I said this is not for the forum it is for another page but the code is the similar. It seems to be working for me now. I ran 5 tests. It seemed to be working last time though and others got errors, so only time will tell. If I redid the error messages and the sql do you think I will be meeting my evil 500 error nemesis anymore?
    Also on the forum you talked about more errors, I think I know which ones you are talking about. Sometimes when you log in I heard if you have a _ in your name it wont display it. That will involve a string where I have to hunt down the "_" character. It will involde some rememberoring on how to do that but it wont be too big of a deal, I have done things like it before where it hinted for the ' character and the / character, so I can actually just copy paste and edit. I never thought of using a string to insert data into my data base, I was using a dbcommand not a string, that cmdstr thing is what I am reffering to. It makes things so much easyer when you are fluent in vb6. Also I have been using vb6 data manager to make my data bases because it is a lot better then my crunny version of access.

  12. #12
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    hi,
    phew!!!!, good something working right. Yes if you fix the errorMessage part of your web controls and rewrite your SQL and then fix this following error im sure you will not see dreaded 500 error for a while

    The following is not correct syntax:

    Code:
    <asp:CompareValidator id="cvPassword"
        ControlToValidate="txtPassword" 
        ControlToCompare="txtPassword2"
        Display="Dynamic"
        Font-Name="Tahoma"
        Font-Size="10pt"
        runat=server>
        Password fields don't match
    </asp:CompareValidator>
    This is the correct syntax
    Code:
    <asp:CompareValidator
    ControlToCompare="txtPassword"
    ControlToValidate="txtPassword2"
    Display="Dynamic"
    ErrorMessage="Password 1 doesn't match password 2"
    Font-Name="Tahoma"
    Font-Size="10pt" 
    id="cvPassword" 
    Operator="Equal"
    runat="server"
    ValueToCompare="txtPassword" >
     </asp:CompareValidator>
    this is allow incorrect:

    Code:
    <%@ Page Language=VB Debug=true %>
    And should be this:
    Code:
    <%@ Page Language="VB" Debug="true" %>
    You should also be using the ASP.NET table tags:

    Code:
    <asp:table runat="server"></asp:table>
    <asp:tablerow runat="server"></asp:tablerow>
    <asp:tablecell runat="server"></asp:tablecell>
    Hope this helps.
    ----------------------------------

  13. #13
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,224
    Im angry as heck because this code a lot of it was just barley modified and came almost stright out of this book I bought. There should not be this many errors. I hunted and hunted for an email or support site so I could express my angor because this is just not right when you pay $45.00 for a big tome of knowledge you expect it to work. But with these modifications this code is running smooth! Now Im off to my message board to begin the daugnting task of error hunting.

  14. #14
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,224
    I have been using mostly html table tags. Easyer to type =) . What ware the advantages to using an asp table tag if it is going to remain static anyway? Like I am not changing the border style or the size width or visibility properties. Thanks for all your help. This has been invaluble to me. This saved me a lot a pain trying to hunt down these problems. Programming can be frustrating at times but it helps a lot to have someone who has a little more experience to help you out at times. When I get more experienced Im sure I will be able to help you help other new asp.neters work through their problems, as tme goes on more people are sure to make the shift from classic to .net

  15. #15
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,224
    found my own error this time
    Code:
    <form runat="server">
    That was driving me nuts I could not figure out what was causing this 500 error. The I saw that I left off a asp: near the top of my code. Hopefully thats the last of them.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles