| @@ -0,0 +1,80 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Security.Claims; | ||
| using System.Security.Principal; | ||
| using System.Web; | ||
| using System.Web.Security; | ||
| using System.Web.UI; | ||
| using System.Web.UI.WebControls; | ||
|
|
||
| namespace Demo | ||
| { | ||
| public partial class SiteMaster : MasterPage | ||
| { | ||
| private const string AntiXsrfTokenKey = "__AntiXsrfToken"; | ||
| private const string AntiXsrfUserNameKey = "__AntiXsrfUserName"; | ||
| private string _antiXsrfTokenValue; | ||
|
|
||
| protected void Page_Init(object sender, EventArgs e) | ||
| { | ||
| // The code below helps to protect against XSRF attacks | ||
| var requestCookie = Request.Cookies[AntiXsrfTokenKey]; | ||
| Guid requestCookieGuidValue; | ||
| if (requestCookie != null && Guid.TryParse(requestCookie.Value, out requestCookieGuidValue)) | ||
| { | ||
| // Use the Anti-XSRF token from the cookie | ||
| _antiXsrfTokenValue = requestCookie.Value; | ||
| Page.ViewStateUserKey = _antiXsrfTokenValue; | ||
| } | ||
| else | ||
| { | ||
| // Generate a new Anti-XSRF token and save to the cookie | ||
| _antiXsrfTokenValue = Guid.NewGuid().ToString("N"); | ||
| Page.ViewStateUserKey = _antiXsrfTokenValue; | ||
|
|
||
| var responseCookie = new HttpCookie(AntiXsrfTokenKey) | ||
| { | ||
| HttpOnly = true, | ||
| Value = _antiXsrfTokenValue | ||
| }; | ||
| if (FormsAuthentication.RequireSSL && Request.IsSecureConnection) | ||
| { | ||
| responseCookie.Secure = true; | ||
| } | ||
| Response.Cookies.Set(responseCookie); | ||
| } | ||
|
|
||
| Page.PreLoad += master_Page_PreLoad; | ||
| } | ||
|
|
||
| protected void master_Page_PreLoad(object sender, EventArgs e) | ||
| { | ||
| if (!IsPostBack) | ||
| { | ||
| // Set Anti-XSRF token | ||
| ViewState[AntiXsrfTokenKey] = Page.ViewStateUserKey; | ||
| ViewState[AntiXsrfUserNameKey] = Context.User.Identity.Name ?? String.Empty; | ||
| } | ||
| else | ||
| { | ||
| // Validate the Anti-XSRF token | ||
| if ((string)ViewState[AntiXsrfTokenKey] != _antiXsrfTokenValue | ||
| || (string)ViewState[AntiXsrfUserNameKey] != (Context.User.Identity.Name ?? String.Empty)) | ||
| { | ||
| throw new InvalidOperationException("Validation of Anti-XSRF token failed."); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected void Page_Load(object sender, EventArgs e) | ||
| { | ||
|
|
||
| } | ||
|
|
||
| protected void Unnamed_LoggingOut(object sender, LoginCancelEventArgs e) | ||
| { | ||
| Context.GetOwinContext().Authentication.SignOut(); | ||
| } | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,23 @@ | ||
| <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.Mobile.master.cs" Inherits="Demo.Site_Mobile" %> | ||
| <%@ Register Src="~/ViewSwitcher.ascx" TagPrefix="friendlyUrls" TagName="ViewSwitcher" %> | ||
|
|
||
| <!DOCTYPE html> | ||
| <html xmlns="http://www.w3.org/1999/xhtml"> | ||
| <head runat="server"> | ||
| <meta name="viewport" content="width=device-width" /> | ||
| <title></title> | ||
| <asp:ContentPlaceHolder runat="server" ID="HeadContent" /> | ||
| </head> | ||
| <body> | ||
| <form id="form1" runat="server"> | ||
| <div> | ||
| <h1>Mobile Master Page</h1> | ||
| <asp:ContentPlaceHolder runat="server" ID="FeaturedContent" /> | ||
| <section class="content-wrapper main-content clear-fix"> | ||
| <asp:ContentPlaceHolder runat="server" ID="MainContent" /> | ||
| </section> | ||
| <friendlyUrls:ViewSwitcher runat="server" /> | ||
| </div> | ||
| </form> | ||
| </body> | ||
| </html> |
| @@ -0,0 +1,17 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Web; | ||
| using System.Web.UI; | ||
| using System.Web.UI.WebControls; | ||
|
|
||
| namespace Demo | ||
| { | ||
| public partial class Site_Mobile : System.Web.UI.MasterPage | ||
| { | ||
| protected void Page_Load(object sender, EventArgs e) | ||
| { | ||
|
|
||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,12 @@ | ||
| using Microsoft.Owin; | ||
| using Owin; | ||
|
|
||
| [assembly: OwinStartupAttribute(typeof(Demo.Startup))] | ||
| namespace Demo | ||
| { | ||
| public partial class Startup { | ||
| public void Configuration(IAppBuilder app) { | ||
| ConfigureAuth(app); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,4 @@ | ||
| <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ViewSwitcher.ascx.cs" Inherits="Demo.ViewSwitcher" %> | ||
| <div id="viewSwitcher"> | ||
| <%: CurrentView %> view | <a href="<%: SwitchUrl %>" data-ajax="false">Switch to <%: AlternateView %></a> | ||
| </div> |
| @@ -0,0 +1,43 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Web; | ||
| using System.Web.Routing; | ||
| using System.Web.UI; | ||
| using System.Web.UI.WebControls; | ||
| using Microsoft.AspNet.FriendlyUrls.Resolvers; | ||
|
|
||
| namespace Demo | ||
| { | ||
| public partial class ViewSwitcher : System.Web.UI.UserControl | ||
| { | ||
| protected string CurrentView { get; private set; } | ||
|
|
||
| protected string AlternateView { get; private set; } | ||
|
|
||
| protected string SwitchUrl { get; private set; } | ||
|
|
||
| protected void Page_Load(object sender, EventArgs e) | ||
| { | ||
| // Determine current view | ||
| var isMobile = WebFormsFriendlyUrlResolver.IsMobileView(new HttpContextWrapper(Context)); | ||
| CurrentView = isMobile ? "Mobile" : "Desktop"; | ||
|
|
||
| // Determine alternate view | ||
| AlternateView = isMobile ? "Desktop" : "Mobile"; | ||
|
|
||
| // Create switch URL from the route, e.g. ~/__FriendlyUrls_SwitchView/Mobile?ReturnUrl=/Page | ||
| var switchViewRouteName = "AspNet.FriendlyUrls.SwitchView"; | ||
| var switchViewRoute = RouteTable.Routes[switchViewRouteName]; | ||
| if (switchViewRoute == null) | ||
| { | ||
| // Friendly URLs is not enabled or the name of the switch view route is out of sync | ||
| this.Visible = false; | ||
| return; | ||
| } | ||
| var url = GetRouteUrl(switchViewRouteName, new { view = AlternateView, __FriendlyUrls_SwitchViews = true }); | ||
| url += "?ReturnUrl=" + HttpUtility.UrlEncode(Request.RawUrl); | ||
| SwitchUrl = url; | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,30 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
|
|
||
| <!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 --> | ||
|
|
||
| <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> | ||
| <!-- | ||
| In the example below, the "SetAttributes" transform will change the value of | ||
| "connectionString" to use "ReleaseSQLServer" only when the "Match" locator | ||
| finds an attribute "name" that has a value of "MyDB". | ||
| <connectionStrings> | ||
| <add name="MyDB" | ||
| connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" | ||
| xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> | ||
| </connectionStrings> | ||
| --> | ||
| <system.web> | ||
| <!-- | ||
| In the example below, the "Replace" transform will replace the entire | ||
| <customErrors> section of your web.config file. | ||
| Note that because there is only one customErrors section under the | ||
| <system.web> node, there is no need to use the "xdt:Locator" attribute. | ||
| <customErrors defaultRedirect="GenericError.htm" | ||
| mode="RemoteOnly" xdt:Transform="Replace"> | ||
| <error statusCode="500" redirect="InternalError.htm"/> | ||
| </customErrors> | ||
| --> | ||
| </system.web> | ||
| </configuration> |
| @@ -0,0 +1,31 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
|
|
||
| <!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 --> | ||
|
|
||
| <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> | ||
| <!-- | ||
| In the example below, the "SetAttributes" transform will change the value of | ||
| "connectionString" to use "ReleaseSQLServer" only when the "Match" locator | ||
| finds an attribute "name" that has a value of "MyDB". | ||
| <connectionStrings> | ||
| <add name="MyDB" | ||
| connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" | ||
| xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> | ||
| </connectionStrings> | ||
| --> | ||
| <system.web> | ||
| <compilation xdt:Transform="RemoveAttributes(debug)" /> | ||
| <!-- | ||
| In the example below, the "Replace" transform will replace the entire | ||
| <customErrors> section of your web.config file. | ||
| Note that because there is only one customErrors section under the | ||
| <system.web> node, there is no need to use the "xdt:Locator" attribute. | ||
| <customErrors defaultRedirect="GenericError.htm" | ||
| mode="RemoteOnly" xdt:Transform="Replace"> | ||
| <error statusCode="500" redirect="InternalError.htm"/> | ||
| </customErrors> | ||
| --> | ||
| </system.web> | ||
| </configuration> |
| @@ -0,0 +1,133 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- | ||
| For more information on how to configure your ASP.NET application, please visit | ||
| http://go.microsoft.com/fwlink/?LinkId=169433 | ||
| --> | ||
| <configuration> | ||
| <configSections> | ||
| <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> | ||
| <section name="entityFramework" | ||
| type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" | ||
| requirePermission="false"/> | ||
| </configSections> | ||
| <connectionStrings> | ||
| <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-Demo-20150807064021.mdf;Initial Catalog=aspnet-Demo-20150807064021;Integrated Security=True" | ||
| providerName="System.Data.SqlClient" /> | ||
| </connectionStrings> | ||
| <system.web> | ||
| <authentication mode="None"/> | ||
| <compilation debug="true" targetFramework="4.5.2"/> | ||
| <httpRuntime targetFramework="4.5.2"/> | ||
| <pages> | ||
| <namespaces> | ||
| <add namespace="System.Web.Optimization"/> | ||
| <add namespace="Microsoft.AspNet.Identity"/> | ||
| </namespaces> | ||
| <controls> | ||
| <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt"/> | ||
| </controls> | ||
| </pages> | ||
| <membership> | ||
| <providers> | ||
| <!-- | ||
| ASP.NET Membership is disabled in this template. Please visit the following link http://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template | ||
| --> | ||
| <clear/> | ||
| </providers> | ||
| </membership> | ||
| <profile> | ||
| <providers> | ||
| <!-- | ||
| ASP.NET Membership Profile is disabled in this template. Please visit the following link http://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template | ||
| --> | ||
| <clear/> | ||
| </providers> | ||
| </profile> | ||
| <roleManager> | ||
| <!-- | ||
| ASP.NET Membership Role is disabled in this template. Please visit the following link http://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template | ||
| --> | ||
| <providers> | ||
| <clear/> | ||
| </providers> | ||
| </roleManager> | ||
| <!-- | ||
| If you are deploying to a cloud environment that has multiple web server instances, | ||
| you should change session state mode from "InProc" to "Custom". In addition, | ||
| change the connection string named "DefaultConnection" to connect to an instance | ||
| of SQL Server (including SQL Azure and SQL Compact) instead of to SQL Server Express. | ||
| --> | ||
| <sessionState mode="InProc" customProvider="DefaultSessionProvider"> | ||
| <providers> | ||
| <add name="DefaultSessionProvider" | ||
| type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" | ||
| connectionStringName="DefaultConnection"/> | ||
| </providers> | ||
| </sessionState> | ||
| </system.web> | ||
| <system.webServer> | ||
| <validation validateIntegratedModeConfiguration="false"/> | ||
| <modules> | ||
| <remove name="FormsAuthentication"/> | ||
| </modules> | ||
| <handlers> | ||
| <remove name="ExtensionlessUrlHandler-Integrated-4.0"/> | ||
| <remove name="OPTIONSVerbHandler"/> | ||
| <remove name="TRACEVerbHandler"/> | ||
| <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" | ||
| preCondition="integratedMode,runtimeVersionv4.0"/> | ||
| </handlers> | ||
| </system.webServer> | ||
| <runtime> | ||
| <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
| <dependentAssembly> | ||
| <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed"/> | ||
| <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/> | ||
| </dependentAssembly> | ||
| <dependentAssembly> | ||
| <assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31bf3856ad364e35"/> | ||
| <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/> | ||
| </dependentAssembly> | ||
| <dependentAssembly> | ||
| <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089"/> | ||
| <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/> | ||
| </dependentAssembly> | ||
| <dependentAssembly> | ||
| <assemblyIdentity name="Microsoft.Owin" culture="neutral" publicKeyToken="31bf3856ad364e35"/> | ||
| <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0"/> | ||
| </dependentAssembly> | ||
| <dependentAssembly> | ||
| <assemblyIdentity name="Microsoft.Owin.Security.OAuth" culture="neutral" publicKeyToken="31bf3856ad364e35"/> | ||
| <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0"/> | ||
| </dependentAssembly> | ||
| <dependentAssembly> | ||
| <assemblyIdentity name="Microsoft.Owin.Security.Cookies" culture="neutral" publicKeyToken="31bf3856ad364e35"/> | ||
| <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0"/> | ||
| </dependentAssembly> | ||
| <dependentAssembly> | ||
| <assemblyIdentity name="Microsoft.Owin.Security" culture="neutral" publicKeyToken="31bf3856ad364e35"/> | ||
| <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0"/> | ||
| </dependentAssembly> | ||
| </assemblyBinding> | ||
| </runtime> | ||
| <entityFramework> | ||
| <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> | ||
| <parameters> | ||
| <parameter value="mssqllocaldb"/> | ||
| </parameters> | ||
| </defaultConnectionFactory> | ||
| <providers> | ||
| <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/> | ||
| </providers> | ||
| </entityFramework> | ||
| <system.codedom> | ||
| <compilers> | ||
| <compiler language="c#;cs;csharp" extension=".cs" | ||
| type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" | ||
| warningLevel="4"/> | ||
| <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" | ||
| type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" | ||
| warningLevel="4"/> | ||
| </compilers> | ||
| </system.codedom> | ||
| </configuration> |
| @@ -0,0 +1,40 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <packages> | ||
| <package id="Antlr" version="3.4.1.9004" targetFramework="net452" userInstalled="true" /> | ||
| <package id="AspNet.ScriptManager.bootstrap" version="3.0.0" targetFramework="net452" userInstalled="true" /> | ||
| <package id="AspNet.ScriptManager.jQuery" version="1.10.2" targetFramework="net452" userInstalled="true" /> | ||
| <package id="bootstrap" version="3.0.0" targetFramework="net452" userInstalled="true" /> | ||
| <package id="EntityFramework" version="6.1.2" targetFramework="net452" userInstalled="true" /> | ||
| <package id="jQuery" version="1.10.2" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.AspNet.FriendlyUrls" version="1.0.2" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.AspNet.FriendlyUrls.Core" version="1.0.2" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.AspNet.Identity.Core" version="2.2.0" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.AspNet.Identity.EntityFramework" version="2.2.0" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.AspNet.Identity.Owin" version="2.2.0" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.AspNet.Providers.Core" version="2.0.0" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.AspNet.ScriptManager.MSAjax" version="5.0.0" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.AspNet.ScriptManager.WebForms" version="5.0.0" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.AspNet.Web.Optimization.WebForms" version="1.1.3" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0-beta1" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.Net.Compilers" version="1.0.0-rc2" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.Owin" version="3.0.1" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.Owin.Host.SystemWeb" version="3.0.1" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.Owin.Security" version="3.0.1" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.Owin.Security.Cookies" version="3.0.1" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.Owin.Security.Facebook" version="3.0.1" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.Owin.Security.Google" version="3.0.1" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.Owin.Security.MicrosoftAccount" version="3.0.1" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.Owin.Security.OAuth" version="3.0.1" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.Owin.Security.Twitter" version="3.0.1" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Modernizr" version="2.6.2" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Owin" version="1.0" targetFramework="net452" userInstalled="true" /> | ||
| <package id="Respond" version="1.2.0" targetFramework="net452" userInstalled="true" /> | ||
| <package id="WebGrease" version="1.5.2" targetFramework="net452" userInstalled="true" /> | ||
| </packages> |