Answered by:
Confirm Email problem with token, valid time for code

Question
-
User-1949524191 posted
Dear All
I have very strange problem with Identity 2.0, during creating new user is genereting email confirm link, when I try use email link after short time everything is fine but when I try use email link after a few hours (2 hours) I got error:
"EmailConfirm Exception: System.NullReferenceException: Object reference not set to an instance of an object. at ASP._Page_Views_Shared_Error_cshtml.Execute ...",
IdentityConfig.cs
if (dataProtectionProvider != null) { manager.UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity")) { TokenLifespan = TimeSpan.FromDays(7) }; }
As you can see I have set this property for 7 days.
Web.config
<system.web> <compilation debug="true" targetFramework="4.5" /> <httpRuntime targetFramework="4.5" maxRequestLength="52428800" executionTimeout="60" /> <roleManager enabled="false" /> <globalization culture="en-GB" uiCulture="en-GB" /> <customErrors mode="Off" /> </system.web> <system.webServer> <modules> <remove name="FormsAuthentication" /> </modules> </system.webServer>
Moreover I read in documentaton that default expire time for this code is 24 hrs, is it true?
Is there something miss? I have not idea how to resolve it. Any help will be appreciated.
Regards
Krzysztof
Monday, March 14, 2016 9:30 PM
Answers
-
User-1949524191 posted
I think I found solution, problem is with hosting which stops the processes after 30 minutes inaction on web and session in mode "In-Process" which is killing all sessions after stops the processes. In my case should only add in Web.config file in <system.web> section
<sessionState mode="StateServer" timeout="120" stateConnectionString="tcpip=127.0.0.1:right-port" cookieless="false" /> <machineKey validationKey="...." decryptionKey="...." validation="SHA1" decryption="AES" />
where "timeout" is valid session in minutes. I set only 2 hrs for tests. I canceled "TokenLifespan = TimeSpan.FromDays(7)"
And voila.
I hope that I wrote with understanding in English.
Regards
Krzysztof
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, March 15, 2016 8:28 PM
All replies
-
User-986267747 posted
Hi kszymaniak,
Moreover I read in documentaton that default expire time for this code is 24 hrs, is it true?TokenLifespan = TimeSpan.FromDays(7)Yes, The default TokenLifespan is one day. In my experience, with the code above, we could set the UserTokenProvider token expiration, the email confirmation tokens will expire in 7 days. Your code seems fine. You could find the related information in the following link.
when I try use email link after short time everything is fine but when I try use email link after a few hours (2 hours) I got error:
"EmailConfirm Exception: System.NullReferenceException: Object reference not set to an instance of an object. at ASP._Page_Views_Shared_Error_cshtml.Execute ...",
According to the error message, i'm not sure why do we get this problem. I suggest that you could debug your code and find the code line where caused this problem.
Best Regards,
Klein zhang
Tuesday, March 15, 2016 4:14 AM -
User-1949524191 posted
Thank you Klein for yr reply.
I looked into link and quote:
"In the Package Manager Console, enter the following the following commands:
Install-Package SendGrid (not installed, I am using smtp client) Install-Package -Prerelease Microsoft.AspNet.Identity.Samples (I am not sure that installed, I have to check, but in short time is working)"
Debug. The web is building with succsesfull with option "Debug" I think that problem is with expire time for security code.
Regards
Krzysztof
Tuesday, March 15, 2016 7:45 AM -
User-1949524191 posted
Dear All
I have additional question about it, pls let me knoe if token code is storing in session? I mean
<sessionState mode="StateServer" ... />
Thanks
Regards
Tuesday, March 15, 2016 9:40 AM -
User-1949524191 posted
I think I found solution, problem is with hosting which stops the processes after 30 minutes inaction on web and session in mode "In-Process" which is killing all sessions after stops the processes. In my case should only add in Web.config file in <system.web> section
<sessionState mode="StateServer" timeout="120" stateConnectionString="tcpip=127.0.0.1:right-port" cookieless="false" /> <machineKey validationKey="...." decryptionKey="...." validation="SHA1" decryption="AES" />
where "timeout" is valid session in minutes. I set only 2 hrs for tests. I canceled "TokenLifespan = TimeSpan.FromDays(7)"
And voila.
I hope that I wrote with understanding in English.
Regards
Krzysztof
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, March 15, 2016 8:28 PM