Jump to content
999ANDRE999

erro ao publicar

Recommended Posts

999ANDRE999

Olá pessoal,

Tenho um projecto feito em asp.net c#. Quando faço run (F5), o VS compila o codigo e executa tudo direitinho. Quando faço Publish website no fim de compilar dá o erro: 

Error    2    Object reference not set to an instance of an object.        
 

Alguém me sabe explicar porque? :confused:

Share this post


Link to post
Share on other sites
13dev

Olá, isso depende que qual .NET Estás a usar , se puderes partilha o teu código e tentarei ajudar.

Share this post


Link to post
Share on other sites
999ANDRE999
19 horas atrás, 13dev disse:

Olá, isso depende que qual .NET Estás a usar , se puderes partilha o teu código e tentarei ajudar.

O meu codigo asp é:

<%@ Page Title="Add defect" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="add_defect.aspx.cs" Inherits="Production_add_defect" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<script runat="server">

</script>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <script language="javascript" type="text/javascript">
    </script>
    <style type="text/css">
        #Text1
        {
            width: 330px;
        }
        #Text2
        {
            width: 330px;
        }
        #Text3
        {
            width: 330px;
        }
        #Text4
        {
            width: 330px;
        }
        #Text5
        {
            width: 330px;
        }
        #Text6
        {
            height: 32px;
            width: 325px;
        }
        #Text13
        {
            width: 330px;
        }
        #Text7
        {
            width: 330px;
        }
        #Text8
        {
            width: 330px;
        }
        #Text13
        {
            width: 330px;
        }
        #Text9
        {
            width: 330px;
        }
        #Text10
        {
            width: 330px;
        }
        #Text11
        {
            width: 330px;
        }
        #Text12
        {
            width: 330px;
        }
        #Submit1
        {
            width: 59px;
        }
        #save_button
        {
            width: 70px;
        }
        .style11
        {
            text-align: center;
        }
        .style13
        {
            height: 25px;
        }
        .style14
        {
            height: 25px;
        }
        .style15
        {
            width: 742px;
        }
    </style>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2 class="style11">
        ADD DEFECT</h2>
    <p align="center">
        <table style="width: 100%;" align="center">
            <tr>
                <td style="text-align: right" class="style14">
                    Nutzen 2D:
                </td>
                <td style="text-align: left" class="style13">
                    <asp:TextBox ID="TextBox1" runat="server" Width="383px" CssClass="textEntry"></asp:TextBox>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <%--<td style="text-align: right" class="style13">
                    Date:
                </td>
                <td style="text-align: left" class="style13">
                    <asp:TextBox ID="TextBox2" runat="server" Width="383px" CssClass="textEntry" ReadOnly="True"></asp:TextBox>
                </td>--%>
            </tr>
            <tr>
                <%--<td style="text-align: right" class="style14">
                    Shift:
                </td>
                <td style="text-align: left" class="style13">
                    <asp:TextBox ID="TextBox3" runat="server" Width="383px" CssClass="textEntry"></asp:TextBox>
                    &nbsp;
                </td>--%>
            </tr>
            <tr>
                <td style="text-align: right" class="style15">
                    Line:
                </td>
                <td style="text-align: left">
                    <asp:TextBox ID="TextBox4" runat="server" Width="383px" CssClass="textEntry"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <%--<td style="text-align: right" class="style14">
                    Product:
                </td>
                <td style="text-align: left" class="style13">
                    <asp:TextBox ID="TextBox5" runat="server" Width="383px" CssClass="textEntry"></asp:TextBox>
                </td>--%>
            </tr>
            <tr>
                <td style="text-align: right" class="style13">
                    Side:
                </td>
                <td style="text-align: left" class="style13">
                    <asp:DropDownList ID="DropDownList2" runat="server" Height="25px" Width="383px">
                        <asp:ListItem>Top</asp:ListItem>
                        <asp:ListItem>Bottom</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td style="text-align: right" class="style15">
                    Part Number:
                </td>
                <td style="text-align: left">
                    <asp:TextBox ID="TextBox7" runat="server" Width="383px" CssClass="textEntry"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td style="text-align: right" class="style15">
                    Ref. position:
                </td>
                <td style="text-align: left">
                    <asp:TextBox ID="TextBox8" runat="server" Width="383px" CssClass="textEntry"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td style="text-align: right" class="style15">
                    Defect:
                </td>
                <td style="text-align: left">
                    <asp:DropDownList ID="DropDownList1" runat="server" Height="25px" Width="383px">
                        <asp:ListItem>2D Code: 2D Position</asp:ListItem>
                        <asp:ListItem>2D Code: Burn/Raw Material
                        </asp:ListItem>
                        <asp:ListItem>2D Code: Incomplete, overlap pcbs
                        </asp:ListItem>
                        <asp:ListItem>2D Code: Missing 2D
                        </asp:ListItem>
                        <asp:ListItem>2D Code: Not Read
                        </asp:ListItem>
                        <asp:ListItem>2D Code: PCB Position
                        </asp:ListItem>
                        <asp:ListItem>Component:  OCR Missing/unrecognizable
                        </asp:ListItem>
                        <asp:ListItem>Component: Damaged/Broken
                        </asp:ListItem>
                        <asp:ListItem>Component: Lifted/Tomb Stone
                        </asp:ListItem>
                        <asp:ListItem>Component: Lost/Foreign
                        </asp:ListItem>
                        <asp:ListItem>Component: Missing
                        </asp:ListItem>
                        <asp:ListItem>Component: Polarity
                        </asp:ListItem>
                        <asp:ListItem>Component: Pulled
                        </asp:ListItem>
                        <asp:ListItem>Component: Shifted
                        </asp:ListItem>
                        <asp:ListItem>Component: Side Stand
                        </asp:ListItem>
                        <asp:ListItem>Component: Upside Down
                        </asp:ListItem>
                        <asp:ListItem>Design: Component PAD/Footprint
                        </asp:ListItem>
                        <asp:ListItem>False Reject
                        </asp:ListItem>
                        <asp:ListItem>PCB: Defective/Solder Mask
                        </asp:ListItem>
                        <asp:ListItem>Process: PCB Contamination
                        </asp:ListItem>
                        <asp:ListItem>Rejected PCB/PCBA
                        </asp:ListItem>
                        <asp:ListItem>Solder Paste: Contamination/Dragged
                        </asp:ListItem>
                        <asp:ListItem>Solder Paste: Excessive
                        </asp:ListItem>
                        <asp:ListItem>Solder Paste: Missing
                        </asp:ListItem>
                        <asp:ListItem>Solder Paste: Poor/Lack
                        </asp:ListItem>
                        <asp:ListItem>Solder Paste: Smearing/Contamination
                        </asp:ListItem>
                        <asp:ListItem>Soldering: Component Wettability
                        </asp:ListItem>
                        <asp:ListItem>Soldering: Fillet
                        </asp:ListItem>
                        <asp:ListItem>Soldering: Pad PCB Dewetting/Wettability
                        </asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td style="text-align: right" class="style15">
                    Number board:
                </td>
                <td style="text-align: left">
                    <asp:TextBox ID="TextBox12" runat="server" Width="383px" CssClass="textEntry"></asp:TextBox>
                </td>
            </tr>
        </table>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </p>
    <asp:Panel ID="Panel1" runat="server" HorizontalAlign="Center" DefaultButton="Button2">
        <%--<p align="center">--%>
                <asp:Button ID="Button2" runat="server" BackColor="White" 
            BorderColor="White" BorderStyle="None" ForeColor="White" Height="16px" 
            Width="17px" onclick="Button2_Click" />
            &nbsp;<asp:Button ID="SaveButton" runat="server" CommandName="Save" Text="Save" Width="54px"
                BackColor="#565656" BorderColor="#565656" ForeColor="White" Font-Bold="True"
                Font-Size="Small" OnClick="SaveButton_Click" />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="Back_button" runat="server" Text="Back" Width="54px" BackColor="#565656"
                BorderColor="#565656" ForeColor="White" Font-Bold="True" Font-Size="Small" OnClick="Back_button_Click" />
        <%--</p>--%>
        &nbsp;&nbsp;&nbsp;

    </asp:Panel>
    <p align="center">
        &nbsp;</p>
    <%--<asp:Panel ID="Panel_Search_Project" runat="server" HorizontalAlign="Center" ScrollBars="Auto"
        EnableViewState="True">
        <h2>
        </h2>
    </asp:Panel>
    <asp:Panel ID="Panel_gridview_project" runat="server" HorizontalAlign="Center">
    </asp:Panel>--%>
</asp:Content>

o c#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Globalization;
using System.Text.RegularExpressions;


public partial class Production_add_defect : System.Web.UI.Page
{
    public string username = HttpContext.Current.User.Identity.Name;//nome do utilizador

    #region Page load
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Request.IsAuthenticated)//não autenticado
        {
            Response.Redirect("~/Account/Login.aspx");
        }

        if (!Page.IsPostBack)
        {
            TextBox1.Focus();
        }

    }
    #endregion

    #region Botão back
    protected void Back_button_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Departments/Production/defects.aspx");
    }
    #endregion

    #region Botão Save
    protected void SaveButton_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text == "" || TextBox1.Text.Length < 20)
        {
            ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "ClientScript", "alert('Invalid Nutzen ID!!')", true);

            TextBox1.Text = null;
            TextBox4.Text = null;
            TextBox7.Text = null;
            TextBox8.Text = null;
            TextBox12.Text = null;
        }

        else
        {
            DataBase.Conecta();
            Npgsql.NpgsqlCommand comm = new Npgsql.NpgsqlCommand();
            comm.Connection = DataBase.Conn;

            comm.Parameters.AddWithValue("@nutzen", TextBox1.Text);
            comm.Parameters.AddWithValue("@linha", TextBox4.Text);
            comm.Parameters.AddWithValue("@component", TextBox7.Text);
            comm.Parameters.AddWithValue("@position", TextBox8.Text);
            comm.Parameters.AddWithValue("@board", TextBox12.Text);

            string defect = DropDownList1.SelectedValue.ToString();
            string side = DropDownList2.SelectedValue.ToString();

            string data = DateTime.Now.ToString("dd-MM-yyyy");
            string hora_ = DateTime.Now.ToString("HH");
            int hora = Convert.ToInt32(hora_);
            string min_ = DateTime.Now.ToString("mm");
            int min = Convert.ToInt32(min_);
            string sec_ = DateTime.Now.ToString("ss");
            int sec = Convert.ToInt32(sec_);

            //string product = TextBox1.Text.Substring(TextBox1.Text.Length - 11);
            string[] product_ = TextBox1.Text.Split('B');
            string product__ = product_[0];
            string product___ = product__.Substring(product__.Length - 5);
            string product = product___.Remove(product___.Length - 1);

            Npgsql.NpgsqlDataAdapter myDataAdapter = new Npgsql.NpgsqlDataAdapter();
            myDataAdapter.SelectCommand = comm;
            DataSet myDataSet = new DataSet();
            int project_already_exist = myDataAdapter.Fill(myDataSet);


            if (hora >= 00 && min >= 00 && sec >= 00 && hora <= 05 && min <= 59 && sec <= 59)
            {
                comm.CommandText = " INSERT INTO defeitos_smt(nutzen, date_, shift, line, product, side, component, position_, defect, board)" +
                "VALUES (@nutzen, '" + data + "', '1', @linha, '" + product + "', '" + side + "',  @component, @position, '" + defect + "', @board) ";
                comm.ExecuteNonQuery();
            }

            if (hora >= 06 && min >= 00 && sec >= 00 && hora <= 14 && min <= 59 && sec <= 59)
            {
                comm.CommandText = " INSERT INTO defeitos_smt(nutzen, date_, shift, line, product, side, component, position_, defect, board)" +
                "VALUES (@nutzen, '" + data + "', '2', @linha, '" + product + "', '" + side + "',  @component, @position, '" + defect + "', @board) ";
                comm.ExecuteNonQuery();
            }

            if (hora >= 15 && min >= 00 && sec >= 00 && hora <= 23 && min <= 59 && sec <= 59)
            {
                comm.CommandText = " INSERT INTO defeitos_smt(nutzen, date_, shift, line, product, side, component, position_, defect, board)" +
                "VALUES (@nutzen, '" + data + "', '3', @linha, '" + product + "', '" + side + "',  @component, @position, '" + defect + "', @board) ";
                comm.ExecuteNonQuery();
            }

            DataBase.Desconecta();

            ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "ClientScript", "alert('New defect created')", true);

            TextBox1.Text = null;
            TextBox4.Text = null;
            TextBox7.Text = null;
            TextBox8.Text = null;
            TextBox12.Text = null;
        }
    }
    #endregion

    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox4.Focus();
    }
}

e o web.config:

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <connectionStrings>
    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.net>
    <defaultProxy>
      <proxy proxyaddress="http://10.32.19.254:8080" bypassonlocal="true"/>
    </defaultProxy>
  </system.net>
  <system.web>
    <customErrors mode="Off"/>
    <httpHandlers>
      <add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false"/>
    </httpHandlers>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="Microsoft.ReportViewer.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="Microsoft.Build.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Net, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
      </assemblies>
      <buildProviders>
        <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      </buildProviders>
    </compilation>
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
    </authentication>
    <membership>
      <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
      </providers>
    </membership>
    <profile>
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
      </providers>
    </profile>
    <roleManager enabled="false">
      <providers>
        <clear/>
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/>
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>
      </providers>
    </roleManager>
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <validation validateIntegratedModeConfiguration="false"/>
    <handlers>
      <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    </handlers>
  </system.webServer>
  <system.serviceModel>
    <bindings/>
    <client/>
  </system.serviceModel>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-2.2.29.0" newVersion="2.2.29.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-2.2.29.0" newVersion="2.2.29.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <appSettings>
  <add key="ws_zerarreel.WSExternal" value="http://bpatravr02/WSExternalCS/WSExternal.asmx"/>
  </appSettings>
</configuration>

 

Share this post


Link to post
Share on other sites
999ANDRE999

e a mensagem de erro que dá é:


Server Error in '/Portal_andre_V6' Application.

Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation. 
  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.ArgumentException: Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

Source Error: 


 An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 



[ArgumentException: Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.]
   System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +9748914
   System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +108
   System.Web.UI.WebControls.DropDownList.LoadPostData(String postDataKey, NameValueCollection postCollection) +64
   System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +18
   System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +457
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1833

  


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1586.0 

 

Share this post


Link to post
Share on other sites
999ANDRE999

colocando <%@ Page EnableEventValidation="false" [..] %> resolveu a minha situação

  • Vote 1

Share this post


Link to post
Share on other sites
13dev

O teu site estará vulnerável a postback requests e callbacks não autorizados ao ter EnableEventValidation desativada!

Poderás resolver o problema sem usar isso uma possível solução é:

Moveres todo teu código de Page_Load para Page_Prerender

  • Vote 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.