I can't login to asp.net web forms application after browser close and open on IIS server

A A 1 Reputation point
2022-11-02T09:43:38.29+00:00

My Application is built using ASP.net Web forms and SQL server

I log in successfully the first time my application is launched. If I close the browser and reopens it, the log in refreshes and brings me back to login page again. Every other thing works as expected but the log in. Please help. I'm using code from the ASP.NET web forms template. I get the same result from other browser types. When I restart the website I can login, logout and without closing the browser everything works fine. but when the browser is closed and opened then I can't login anymore.

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,254 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,709 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,242 questions
{count} votes

3 answers

Sort by: Most helpful
  1. SurferOnWww 1,911 Reputation points
    2022-11-03T01:07:17.767+00:00

    I'm using code from the ASP.NET web forms template.

    If so, there should be a "Remember me" checkbox on the login page created by the template of Visual Studio. Put check mark on the checkbox when login.

    The Set-Cookie header will include an "expires" attribute. It means that the authentication cookie will be stored in a HDD (or SSD) of user's PC and the user will be automatically authenticated even after the user closes the browser and reopens it for a period set by the "expires" atttibute.

    See the following document for details.

    An Overview of Forms Authentication (C#)
    https://learn.microsoft.com/en-us/aspnet/web-forms/overview/older-versions-security/introduction/an-overview-of-forms-authentication-cs

    0 comments No comments

  2. A A 1 Reputation point
    2022-11-06T18:46:19.8+00:00

    Below is my code sample for the login page which is generated by the Visual Studio Web forms template.
    When the Application is running on Localhost, I observed that once am able to successfully login to the Application from one browser (say, Chrome), login attempt returns me to the default page without being authenticated. It is important that I mention that the Application is running well and does not crash, regardless of what browser is used. The issue is the login difficulty to the Application once I have made a first successful attempt. I could log in and out on that particular browser any amount of times as long as I don't close the browser.

    using System;
    using System.Web;
    using System.Web.UI;
    using Microsoft.AspNet.Identity;
    using Microsoft.AspNet.Identity.Owin;
    using Owin;
    using myPortal.Models;

    namespace myPortal.Account
    {
    public partial class Login : Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    RegisterHyperLink.NavigateUrl = "Register";
    // Enable this once you have account confirmation enabled for password reset functionality
    //ForgotPasswordHyperLink.NavigateUrl = "Forgot";
    //OpenAuthLogin.ReturnUrl = Request.QueryString["ReturnUrl"];
    var returnUrl = HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
    if (!String.IsNullOrEmpty(returnUrl))
    {
    RegisterHyperLink.NavigateUrl += "?ReturnUrl=" + returnUrl;
    }
    }

        protected void LogIn(object sender, EventArgs e)  
        {  
            if (IsValid)  
            {  
                // Validate the user password  
                var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();  
                var signinManager = Context.GetOwinContext().GetUserManager<ApplicationSignInManager>();  
    
                // This doen't count login failures towards account lockout  
                // To enable password failures to trigger lockout, change to shouldLockout: true  
                var result = signinManager.PasswordSignIn(Email.Text, Password.Text, RememberMe.Checked, shouldLockout: false);  
    
                switch (result)  
                {  
                    case SignInStatus.Success:  
                        IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);  
                        break;  
                    case SignInStatus.LockedOut:  
                        Response.Redirect("/Account/Lockout");  
                        break;  
                    case SignInStatus.RequiresVerification:  
                        Response.Redirect(String.Format("/Account/TwoFactorAuthenticationSignIn?ReturnUrl={0}&RememberMe={1}",   
                                                        Request.QueryString["ReturnUrl"],  
                                                        RememberMe.Checked),  
                                          true);  
                        break;  
                    case SignInStatus.Failure:  
                    default:  
                        FailureText.Text = "Invalid login attempt";  
                        ErrorMessage.Visible = true;  
                        break;  
                }  
            }  
        }  
    }  
    

    }

    // SessionState setting on Web.Config file:

    <sessionState mode="InProc" timeout="20" customProvider="DefaultSessionProvider"> </sessionState>


  3. Lan Huang-MSFT 25,551 Reputation points Microsoft Vendor
    2022-11-11T07:11:44.727+00:00

    Hi @A A ,
    Can't log in without an error message? Is it just that the page is not responding?
    I can only guess that maybe your Chart control is not configured correctly(IIS7 required to write handlers inside system.webserver but not in the system.web.), maybe you can reconfigure it by following the steps below.
    1.You need to use this at the top of your aspx page:

    <%@ Register assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI.DataVisualization.Charting" tagprefix="asp" %>    
    

    2.Your web.config must contain the following:

    <appSettings>  
      <add key="ChartImageHandler" value="storage=file;timeout=20;" />  
    </appSettings>  
    

    <compilation debug="true" targetFramework="4.7.2" >  
              <assemblies>  
                  <add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
              </assemblies>  
          </compilation>  
    

    <system.webServer>      
    <handlers>  
          <add name="ChartImg" verb="*" path="ChartImg.axd"  type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"  />  
        </handlers>  
    </system.webServer>  
    

    3.Right click on your project and click "Add"--->"References"--->Assemblies--->add the System.Web.DataVisualization.

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments