Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Viewstate MAC的ASPX页面错误应用程序失败_C#_Asp.net - Fatal编程技术网

C# Viewstate MAC的ASPX页面错误应用程序失败

C# Viewstate MAC的ASPX页面错误应用程序失败,c#,asp.net,C#,Asp.net,我有一个aspx页面,其中有几个字段。当按下按钮时,它会与Dynamics CRM Online对话并在那里创建记录。当表单在外部使用时会显示此错误,并且似乎只有某些人会出现此错误-我无法在我的计算机上复制它。该网站托管在Azure网站上 我不确定需要共享哪些代码,但我尝试添加了两个代码片段: <machineKey validationKey='...' decryptionKey='...' validation='SHA1'/> <pages validateReque

我有一个aspx页面,其中有几个字段。当按下按钮时,它会与Dynamics CRM Online对话并在那里创建记录。当表单在外部使用时会显示此错误,并且似乎只有某些人会出现此错误-我无法在我的计算机上复制它。该网站托管在Azure网站上

我不确定需要共享哪些代码,但我尝试添加了两个代码片段:

<machineKey validationKey='...' decryptionKey='...' validation='SHA1'/>
 <pages validateRequest="false"
     enableEventValidation="false"
     viewStateEncryptionMode ="Never"
    enableViewStateMac="false">
到web.config,但仍然会得到错误。我不确定我需要去哪里解决这个问题

单击按钮时运行的代码:

protected void checkCSN(object sender, EventArgs e)
    {
        System.Web.UI.WebControls.Label confirmLabel = new System.Web.UI.WebControls.Label();
        confirmLabel.Text = "Thank you for submitting the request.<br />Someone will be in touch shortly.";

        Microsoft.Xrm.Client.CrmConnection connection = CrmConnection.Parse(GetServiceConfiguration());
        _service = new OrganizationService(connection);
        string fetchCompany = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                                      <entity name='account'>
                                        <attribute name='accountid' />
                                        <attribute name='ownerid' />
                                        <attribute name='name' />
                                        <filter type='and'>
                                          <condition attribute='c20_uniquesupportnumber' operator='eq' value='" + csn.Text + @"' />
                                        </filter>
                                      </entity>
                                    </fetch>";

        string fetchCon = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                                                    <entity name='contact'>
                                                        <attribute name='contactid' />
                                                        <attribute name='new_teamviewerid' />
                                                        <attribute name='new_teamviewerpw' />
                                                        <attribute name='ownerid' />
                                                        <filter type='and'>
                                                          <condition attribute='emailaddress1' operator='eq' value='" + email.Text + @"' />
                                                        </filter>
                                                      </entity>
                                                    </fetch>";

        EntityCollection cl = _service.RetrieveMultiple(new FetchExpression(fetchCompany));
        if (cl.Entities.Count == 1)
        {
            EntityReference client = new EntityReference("account", (Guid)cl.Entities[0].Attributes["accountid"]);

            Entity incident = new Entity("incident");
            EntityCollection cn = _service.RetrieveMultiple(new FetchExpression(fetchCon));
            if (cn.Entities.Count > 0)
            {
                EntityReference contact = new EntityReference("contact", (Guid)cn.Entities[0].Attributes["contactid"]);

                incident["c20_contact"] = contact;
                if (cn.Entities[0].Contains("new_teamviewerid") && cn.Entities[0].Attributes["new_teamviewerid"].ToString().Length > 0)
                {
                    incident["c20_teamviewercode"] = cn.Entities[0].Attributes["new_teamviewerid"].ToString();
                }
                if (cn.Entities[0].Contains("new_teamviewerpw") && cn.Entities[0].Attributes["new_teamviewerpw"].ToString().Length > 0)
                {
                    incident["new_password"] = cn.Entities[0].Attributes["new_teamviewerpw"].ToString();
                }
                incident["customerid"] = client;
                incident["title"] = product.Text + " Support";
                incident["description"] = description.Text;
                incident["ownerid"] = (EntityReference)cl.Entities[0].Attributes["ownerid"];

                incident["casetypecode"] = new OptionSetValue((int)3);

                Guid incidentId = _service.Create(incident);

                Entity ins = _service.Retrieve("incident", incidentId, new ColumnSet("ticketnumber"));
                incident.Id = incidentId;
                incident["title"] = product.SelectedItem + " Support: " + ins.Attributes["ticketnumber"].ToString();
                _service.Update(incident);
            }
            else
                confirmLabel.Text = "Invalid email address. Please contact your administrator.";

        }
        else if (cl.Entities.Count == 0)
            confirmLabel.Text = "No matching accounts with that support number. Please contact your administrator.";
        else
            confirmLabel.Text = "Invalid number of matching accounts with that support number. Please contact your administrator.";

        confirmPanel.Controls.Add(confirmLabel);
    }
完全跟踪。如果我删除了任何重要内容,请道歉

Server Error in '/' Application.
--------------------------------------------------------------------------------


Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

See http://go.microsoft.com/fwlink/?LinkID=314055 for more information. 
  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.Web.HttpException: Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

See http://go.microsoft.com/fwlink/?LinkID=314055 for more information.

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: 

[ViewStateException: Invalid viewstate. 
Client IP: ....
Port: 1094
Referer: http://domain.azurewebsites.net/CreateCase
Path: /CreateCase
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)
ViewState: ...]

[HttpException (0x80004005): Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

See http://go.microsoft.com/fwlink/?LinkID=314055 for more information.]
System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) +116
System.Web.UI.ObjectStateFormatter.Deserialize(String inputString, Purpose purpose) +432
 System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter2.Deserialize(String serializedState, Purpose purpose) +8
System.Web.UI.Util.DeserializeWithAssert(IStateFormatter2 formatter, String serializedState, Purpose purpose) +40
System.Web.UI.HiddenFieldPageStatePersister.Load() +248
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +272
System.Web.UI.Page.LoadAllState() +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6704
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint,  Boolean includeStagesAfterAsyncPoint) +245
System.Web.UI.Page.ProcessRequest() +72
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +58
ASP.createcase_aspx.ProcessRequest(HttpContext context) +37
  System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET     Version:4.0.30319.36215 

不确定,因此我不会将其作为答案发布,但我怀疑,由于Azure托管,用于验证viewstate和生成MAC的密钥在往返过程中不一致。或者,受影响的客户端在提交之前正在做一些改变viewstate的事情,这导致了MAC的失败。我认为客户端不会做任何“故意”的事情,所以这将是我需要处理的事情。可以测试密钥是否为consent吗?哦,不,我不是指用户,我是指客户端机器。MAC验证是在幕后进行的。您可以探索一个常量机器密钥的规范,以检查此可能性,并了解其澄清-我的错。web中的项是否能够处理这个问题,因为它仍然给出了其中的错误。我使用了从这里生成的密钥:这会导致问题吗?