When I tried to submit a specific form the session becomes expire.
Please don't relate this problem to the session timeout. I've tested with other forms all are working fine but when I tried to submit a specific form the sessions become expire.
Here is my [SessionExpire]
attribute that I'm using to ensure that session is not expire.
public class SessionExpireAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpContext ctx = HttpContext.Current;
// check sessions here
if (HttpContext.Current.Session["createdby"] == null)
{
filterContext.Result = new RedirectResult("~/Account/Login");
return;
}
base.OnActionExecuting(filterContext);
}
}
Here is my Controller action
[SessionExpire]
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Edit([Bind(Include = "FirmId,Name,Email,Phone,Status,CellPhone,UnitLimit,Address,PaymentDate,NextPaymentDate,Currency,NoUnit,NoProperty,ExpectedNoUnit,BusinessType,Website,ClientId,CreatedDate,CreatedBy,DeletedBy,DeletedOn,PackageId,IsCustomPackage")] FirmDM objFirm, HttpPostedFileBase fileLogo, HttpPostedFileBase fileSign)
{
//My logic
}
Here is my form
@using (Html.BeginForm("Edit", "Firm", FormMethod.Post, new { enctype = "multipart/form-data", @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
//My input fields
<input type="submit" class="btn btn-default" value="Save" />
}
I found many questions about session expiring on Stack Overflow like this but couldn't solve problem. I'm curious, why my session value becomes null when submit a specific form not at all?
Please ask for if need any other information.