C를 사용한 샘플 ASP.NET 쿠키를 사용한 Sharp 리디렉션
이 샘플 ASP .NET 코드는 간단한 인증 포털을 만들고 암호화되지 않은 HTTP 헤더를 쿠키로 전달합니다.
주:
여기에 설명된 기능을 사용하려면 관리자 역할이 필요합니다.
주:
쿠키는 도메인에 따라 다르며 다른 네트워크 도메인에서 사용할 수 없습니다. 쿠키를 읽을 수 있는 유일한 도메인은 쿠키를 설정하는 도메인입니다. 어떤 도메인 이름을 설정했는지는 중요하지 않습니다. SSO 포털이 인스턴스와 ServiceNow 동일한 네트워크 도메인에 있는 옵션이 없는 경우(예: 온프레미스 배포의 경우 URL GET 또는 POST 매개변수를 사용하여 SSO 토큰을 전달하는 대안이 있습니다.
이 샘플에서는 다음을 가정합니다.
- 웹 서버는 ASP .NET 및 C를 지원합니다.#
- 대상 ServiceNow 인스턴스는 https://<instance name>.service-now.com/ 입니다.
- SiteMinder 또는 다른 Single Sign-On 응용 프로그램이 사용자를 사전 인증했습니다.
- 대상 ServiceNow인스턴스에 다음의 HTTP 헤더가 필요합니다SM_USER
사용자를 적절한 ServiceNow 인스턴스로 리디렉션하도록 ASP 코드를 변경합니다.
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Portal Page Login</title>
<%-- <meta http-equiv="REFRESH" content="0;url=https://<instance name>.service-now.com/">--%>
</head>
<body>
<form id="form1" runat="server">
<h2><b> Portal Page Login </b></h2>
<hr style="position: static" />
<br />
<asp:Label ID="Label2" runat="server" Font-Size="Larger" Height="21px" Style="position: static"
Text="Instance URL:" Width="113px"></asp:Label>
<asp:TextBox ID="urlBox" runat="server" Font-Size="Large" Style="position: static"></asp:TextBox><br />
<br />
<asp:Label ID="Label1" runat="server" Font-Size="Larger" Height="17px" Style="position: static;" Text="User Id:" Width="113px"></asp:Label>
<asp:TextBox ID="userNameBox" runat="server" Font-Size="Large" Style="position: static;"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Height="39px" Style="position: static;" Text="Ok"
Width="88px" OnClick="Button1_click" />
</form>
</body>
</html>
</asp>다음 C# 코드에서는 폼에 대한 OnClick 단추 이벤트를 처리합니다. 코드는 다음과 같습니다.
- 쿠키 "SM_USER"를 작성합니다.
- ASP 양식에 지정된 URL로 리디렉션을 수행합니다.
C# 코드를 변경하여 적절한 쿠키 이름을 만듭니다.
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 {}
}
}