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="name@example.com" />
</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