Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
672 views
in Technique[技术] by (71.8m points)

c# - ASP.NET Core Razor - File Upload - RequestFormLimits - antiforgery token could not be decrypted

In SendFile.cshtml.cs

[RequestFormLimits(MultipartBodyLengthLimit = 2097152)]
public class SendFileModel : PageModel

In SendFile.cshtml

<form method="post" enctype="multipart/form-data">
    <div class="form-group">
        <label asp-for="Data.UploadFile"></label>
        <input asp-for="Data.UploadFile" class="form-control" accept=".zip" />
    </div>
    <div class="form-group">
        <label asp-for="Data.EmailAddress"></label>
        <input asp-for="Data.EmailAddress" class="form-control" placeholder="[email protected]" />
    </div>
    <input type="submit" value="Send" class="btn btn-primary" />
</form>

It is causing the following exception when the file is larger than the limit:

An exception was thrown while deserializing the token.

Exception: 
Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException: The antiforgery token could not be decrypted.
 ---> System.Security.Cryptography.CryptographicException: The key {xxxxxxxxxx} was not found in the key ring.
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status)
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.DangerousUnprotect(Byte[] protectedData, Boolean ignoreRevocationErrors, Boolean& requiresMigration, Boolean& wasRevoked)
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(Byte[] protectedData)
   at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgeryTokenSerializer.Deserialize(String serializedToken)
   --- End of inner exception stack trace ---
   at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgeryTokenSerializer.Deserialize(String serializedToken)
   at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgery.GetCookieTokenDoesNotThrow(HttpContext httpContext)

Is this correct, or is there a better way to set a upload limit and handle when the file is too large?

Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...