Validation of viewstate MAC failed khi save update trong asp.net

Thảo luận trong 'Lập trình web Asp.net' bắt đầu bởi admin, 12/4/17.

  1. admin
    Tham gia ngày:
    22/5/13
    Bài viết:
    4,883
    Đã được thích:
    1,193
    Điểm thành tích:
    113
    Giới tính:
    Nam
    Lỗi : khi update, save upload lên hosting windows trong asp.net
    Mã:
    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:
    [No relevant source lines]
    Source File: c:\windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\96c4b5e9\43b13487\App_Web_0o4kq2tj.2.cs    Line: 0
    Stack Trace:
    [ViewStateException: Invalid viewstate.
        Client IP: 115.79.145.101
        Port: 2640
        Referer: http://thietkequancafedep.com.vn/Admincp/WAddNewProducts.aspx
        Path: /Admincp/WAddNewProducts.aspx
        User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
        ViewState: /wEPDwUKMTI3MjExMTQ3Mw9kFgJmD2QWAgIDD2QWBAIBDw8WAh4EVGV4dAU7Q2jDumMgYuG6oW4gOiBhZG1pbiBt4buZdCBuZ8OgeSBxdeG6o24gdHLhu4sgdGjDoG5oIGPDtG5nICFkZAIHD2QWFGYPDxYCHwBlZGQCBw8PFgIfAGVkZAIIDw8WAh8AZWRkAhQPDxYCHwBlZGQCFw8PFgIeDkNLRWRpdG9yQ29uZmlnMq9wAAEAAAD/////AQAAAAAAAAAMAgAAAE9DS0VkaXRvci5ORVQsIFZlcnNpb249My42LjYuMiwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1lMzc5Y2RmMmY4MzU0OTk5BQEAAAAbQ0tFZGl0b3IuTkVULkNLRWRpdG9yQ29uZmlnnQAAABNfc2hhcmVkU3BhY2VzQm90dG9tEF9zaGFyZWRTcGFjZXNUb3AlPGF1dG9Hcm93X2JvdHRvbVNwYWNlPmtfX0JhY2tpbmdGaWVsZCM8YXV0b0dyb3dfbWF4SGVpZ2h0PmtfX0JhY2tpbmdGaWVsZCM8YXV0b0dyb3dfbWluSGVpZ2h0PmtfX0JhY2tpbmdGaWVsZCM8YXV0b0dyb3dfb25TdGFydHVwPmtfX0JhY2tpbmdGaWVsZB48YXV0b1BhcmFncmFwaD5rX19CYWNraW5nRmllbGQiPGF1dG9VcGRhdG...]
    [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) +425
       System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter2.Deserialize(String serializedState, Purpose purpose) +13
       System.Web.UI.Util.DeserializeWithAssert(IStateFormatter2 formatter, String serializedState, Purpose purpose) +40
       System.Web.UI.HiddenFieldPageStatePersister.Load() +247
       System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +251
       System.Web.UI.Page.LoadAllState() +41
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6211
       System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +245
       System.Web.UI.Page.ProcessRequest() +72
       System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +22
       System.Web.UI.Page.ProcessRequest(HttpContext context) +58
       ASP.admincp_waddnewproducts_aspx.ProcessRequest(HttpContext context) in c:\windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\96c4b5e9\43b13487\App_Web_0o4kq2tj.2.cs:0
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +188
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1087.0
    
    Validation-of-viewstate-MAC-failed.png

    Lỗi : 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
    • Lỗi do web bạn không sinh được machineKey.
    Cách khắc phục như sau:

    Cách 1: Xử lý tại web.config
    • Vào trang web sau, và click vào nút Generate key đế lấy 1 đoạn code và cho vào web.config của web.
    • Tùy web bạn là 1.1 hay 2.0 mà lấy đúng đoạn code.
    Mã:
    http://www.developerfusion.com/tools/generatemachinekey/
    
    • Lấy key xong vào web.config điền vào trong của <system.web> nhé.
    • Nếu không được thì bạn sử dụng thử key ở dưới của mình xem được không!
    Mã:
    <system.web>
          <machineKey decryption="Auto" decryptionKey="2FBFBBE197D2F59485E4D88D06B8EA8E742AE630B3118DCC,IsolateApps" validationKey="0B62A3583B852025FF269D33F18ED2EBC16B3D0ABBFE6311F32CD8AD13BFF05AEA0940C7F5417AF27C58683F3694361C507F9892467D7B8591A3EF01C868AC7C,IsolateApps" />
    </system.web>
    
    • Nếu bạn bỏ vào mà vẫn bị lỗi. Thì suy ra cái key đó vẫn chưa đúng.
    • Bạn gọi cho bên hosting, gửi cho họ cái hình lỗi ở trên và nói họ cho bạn cái machineKey của hosting. Và họ sẽ cho bạn cái key, Chèn vô là xong ngay.
    • Đảm bảo 100% thành công, vì mình xử lý như vậy cả trăm cái web đều OK.
    Nếu bạn Quản lý HOSTING IIS của web.
    • Nếu bạn là quản trị viên của iis sever web của bạn luôn thì bạn làm như sau.
    • Truy cập vào iss của bạn, Click chọn Machine Key như hình dưới.
    open-iss.jpg
    • Tiếp theo chọn Generate Keys, Copy key này cho vào web bạn là xong.
    generate-keys-machine-asp.net.jpg

    Cách 2: Còn không được nữa thì bạn nói hosting cấu hình web bạn lại xuống từ dotnet 4.5 xuống còn 4.0 là được.

    Chỉ có 2 cách xử lý đó thôi ! chúc bạn thành công !!!
    [/COLOR]
     
    Cảm ơn đã xem bài:

    Validation of viewstate MAC failed khi save update trong asp.net

    Chỉnh sửa cuối: 12/4/17
  2. csx.vn
    Tham gia ngày:
    12/4/17
    Bài viết:
    4
    Đã được thích:
    0
    Điểm thành tích:
    1
    Giới tính:
    Nam
    cám ơn nhiều :):):):):)