Sample ASP.NET with C Sharp redirect with cookies
-
- UpdatedJan 30, 2025
- 2 minutes to read
- Yokohama
- API implementation
This sample ASP .NET code creates a simple authentication portal and passes an unencrypted HTTP header as a cookie.
Note: Functionality described here requires the
Admin role.
Note: Cookies are domain specific and cannot be used across different network domains.
The only domain that can read a cookie is the domain that sets it. It does not matter what domain name you set.
If you do not have an option of your SSO portal being in the same network domain as your ServiceNow instance
(for example, in an on-premisis deployment, an alternative is to pass the SSO token using URL GET or POST parameters.
This sample assumes:
- The web server supports ASP .NET and C#
- The target ServiceNow instance is https://<instance name>.service-now.com/
- SiteMinder or another single sign-on application has pre-authenticated the user
- The target ServiceNow instance expects an HTTP header of SM_USER
Change the ASP code to redirect users to the proper ServiceNow instance.

The following C# code handles the OnClick button event for the form. The code:
- Creates the cookie "SM_USER"
- Performs a redirect to the URL specified on the ASP form.
Change the C# code to create the proper cookie name.