summaryrefslogtreecommitdiffstats
path: root/samples/OAuthServiceProvider/Default.aspx
blob: 67efe3aa6d8067035c31c4fff3f9ea3faba7ef10 (plain)
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
<%@ Page Title="DotNetOpenAuth Service Provider Sample" Language="C#" MasterPageFile="~/MasterPage.master" %>

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">

	protected void createDatabaseButton_Click(object sender, EventArgs e) {
		string dbPath = Path.Combine(Server.MapPath(Request.ApplicationPath), "App_Data");
		if (!Directory.Exists(dbPath)) {
			Directory.CreateDirectory(dbPath);
		}
		string connectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString.Replace("|DataDirectory|", dbPath);
		var dc = new DataClassesDataContext(connectionString);
		if (dc.DatabaseExists()) {
			dc.DeleteDatabase();
		}
		try {
			dc.CreateDatabase();
			// Fill with sample data.
			dc.OAuthConsumers.InsertOnSubmit(new OAuthConsumer {
				ConsumerKey = "sampleconsumer",
				ConsumerSecret = "samplesecret",
			});
			dc.Users.InsertOnSubmit(new User {
				OpenIDFriendlyIdentifier = "=arnott",
				OpenIDClaimedIdentifier = "=!9B72.7DD1.50A9.5CCD",
				Age = 27,
				FullName = "Andrew Arnott",
				FavoriteSites = new System.Data.Linq.EntitySet<FavoriteSite> {
					new FavoriteSite { SiteUrl = "http://www.microsoft.com" },
					new FavoriteSite { SiteUrl = "http://www.google.com" },
				},
			});

			dc.SubmitChanges();
			databaseStatus.Visible = true;
		} catch (System.Data.SqlClient.SqlException ex) {
			foreach (System.Data.SqlClient.SqlError error in ex.Errors) {
				Response.Write(error.Message);
			}
		}
	}
</script>

<asp:Content ID="Content2" ContentPlaceHolderID="Body" runat="Server">
	<asp:Button ID="createDatabaseButton" runat="server" Text="(Re)create Database" OnClick="createDatabaseButton_Click" />
	<asp:Label runat="server" ID="databaseStatus" EnableViewState="false" Text="Database recreated!"
		Visible="false" />
</asp:Content>