forked from ServiceStack/ServiceStack.UseCases
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefault.aspx
More file actions
66 lines (58 loc) · 2.55 KB
/
Copy pathDefault.aspx
File metadata and controls
66 lines (58 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CustomAuthentication._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>
<body>
<div Visible="false" id="phAuthenticated" runat="server" enableviewstate=false style="color:green;">Authenticated.</div>
<form id="form1" runat="server">
<div>
User: <asp:TextBox runat="server" ID="tbUser" CssClass="userName" Text="admin" /> (or "user") <br />
Password: <asp:TextBox runat="server" ID="tbPassword" CssClass="password" Text="123" /> <br />
<asp:Button runat="server" OnClick="btnAuth_Click" Text="ASP.NET Form Login" />
</div>
</form>
<button onclick="ajaxLogin()">Ajax Login</button>
<div class="protectedServices">
<button onclick="helloService()">Invoke Hello Service</button>
</div>
<script>
function ajaxLogin() {
InvokeService('<%=ResolveUrl("~/api/auth")%>',
{ userName: userName = $('.userName').val(), password: $('.password').val() },
function (data, textStatus, jqXHR) {
alert('Authenticated! Now you can run Hello Service.');
}
);
return false;
}
function helloService() {
InvokeService('<%=ResolveUrl("~/api/hello")%>',
{ name: userName = $('.userName').val() },
function (data, textStatus, jqXHR) {
alert(data.Result);
}
);
}
function InvokeService(url, data, success) {
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: data,
url: url,
success: success,
error: function (xhr, textStatus, errorThrown) {
var data = $.parseJSON(xhr.responseText);
if (data === null)
alert(textStatus + " HttpCode:" + xhr.status);
else
alert("ERROR: " + data.ResponseStatus.Message + (data.ResponseStatus.StackTrace ? " \r\n Stack:" + data.ResponseStatus.StackTrace : ""));
}
});
}
</script>
</body>
</html>