single sign-on (SSO) between ASP.NET Core app and ASP.NET Web Forms app
single sign-on (SSO) between your ASP.NET Core app and your legacy ASP.NET Web Forms app using a shared authentication token
Yes, you can achieve single sign-on (SSO) between your ASP.NET Core app and your legacy ASP.NET Web Forms app using a shared authentication token, typically a JWT (JSON Web Token). Here's a high-level approach to make this work:
🛠️ Strategy Overview
-
Authenticate in ASP.NET Core
Use ASP.NET Core Identity or any other authentication mechanism.
Generate a JWT token upon successful login.
-
Pass the Token to Web Forms App
Redirect the user to the Web Forms app with the token in the query string or a cookie.
Example:
https://webformsapp.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
-
Validate Token in Web Forms
In the Web Forms app, intercept the token (e.g., in
Global.asaxor a base page).Use a JWT library (like
System.IdentityModel.Tokens.Jwt) to validate the token.If valid, create a session or authentication cookie for the Web Forms app.
-
Secure the Token Exchange
Use HTTPS to prevent token leakage.
Sign the JWT with a shared secret or certificate.
Set a short expiration time and consider IP or user-agent binding.
🔐 Token Validation in Web Forms (Example)
var token = Request.QueryString["token"];
var tokenHandler = new JwtSecurityTokenHandler();
var validationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidIssuer = "your-core-app",
ValidateAudience = true,
ValidAudience = "your-webforms-app",
ValidateLifetime = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("your-secret-key"))
};
SecurityToken validatedToken;
var principal = tokenHandler.ValidateToken(token, validationParameters, out validatedToken);
// Create session or cookie
Session["User"] = principal.Identity.Name;
✅ Best Practices
Use same domain or subdomains if possible to share cookies.
Consider using OpenID Connect or OAuth2 if both apps can support it.
Store minimal user info in the token (e.g., user ID, roles).
Rotate signing keys periodically.

نظرات (۰)
هیچ نظری هنوز ثبت نشده است