--- title: Sample ASP.NET with C Sharp redirect with cookies description: This sample ASP.NET code creates a simple authentication portal and passes an unencrypted HTTP header as a cookie. locale: en-US canonical_url: https://www.servicenow.com/docs/r/australia/api-reference/web-services/r\_ASPNETCSharpRdrctCks.html release: australia product: Web Services classification: web-services topic_type: reference last_updated: "2026-03-12" reading_time_minutes: 1 breadcrumb: [Examples, Inbound, Web services, API implementation, API implementation and reference] --- # Sample ASP.NET with C Sharp redirect with cookies 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://.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. ``` Portal Page Login <%-- --%>

Portal Page Login







``` 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. ``` using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_click(object sender, EventArgs e) { try { HttpCookie myCookie = new HttpCookie("SM_USER"); myCookie.Value = userNameBox.Text; Response.Cookies.Add(myCookie); Response.Redirect(urlBox.Text); }catch {} } } ``` **Parent Topic:**[Inbound web service examples](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/web-services/c_InboundWebServiceExamples.md)