In our asp.net application we can use Owin to login and/or register with Gmail. After creating a successful login to your asp.net application using gmail. You can still see that the gmail is logged in eventhough you are redirected to your application. The following snippet in the code behind can be executed before the redirection to you main application, so you logout from gmail in the background. You can see tutorial to Configuring Google authentication in ASP.NET Core here

In this snippet, I am using either ClientScript Manager to register the script in the head or Building Javascript and then sending as response.write  so that the image loads the gmail logout link , which in turn logout your gmail account.


string RedirectURL = "dashboard.aspx";

// Define the name and type of the client scripts on the page.

string csname = "GmailLogout";
Type cstype = this.GetType();

// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;

// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname))
{
StringBuilder cstext = new StringBuilder();

cstext.Append("<script type=\"text/javascript\">");
cstext.Append("document.write(\"<img src=\'https://mail.google.com/mail/u/0/?logout&hl=en\' height=\'0\' width=\'0\'/>\");");

cstext.Append("setTimeout(function() {");
cstext.Append("window.location.replace(\"" + RedirectURL + "\");");
cstext.Append("}, 1000);");
cstext.Append("</script>");

//cs.RegisterStartupScript(cstype, csname, cstext.ToString());
Response.Write(cstext.ToString());
Response.End();
}