Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / MIT / System / Web / Mobile / MobileFormsAuthentication.cs / 1305376 / MobileFormsAuthentication.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
using System.Diagnostics;
using System.Security;
using System.Web.Security;
using System.Web.UI.MobileControls;
using System.Security.Permissions;
namespace System.Web.Mobile
{
/*
* MobileFormsAuthentication
* provides mobile comopatible version of ASP.Net methods
*
* Copyright (c) 2000 Microsoft Corporation
*/
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
public class MobileFormsAuthentication
{
// Class only contains statics, so make the constructor private.
private MobileFormsAuthentication()
{
}
///
public static void RedirectFromLoginPage(String userName, bool createPersistentCookie)
{
FormsAuthentication.RedirectFromLoginPage(userName, createPersistentCookie, FormsAuthentication.FormsCookiePath);
}
///
public static void RedirectFromLoginPage(String userName, bool createPersistentCookie, String strCookiePath)
{
FormsAuthentication.RedirectFromLoginPage(userName, createPersistentCookie, strCookiePath);
/*
// Disallow redirection to an absolute url.
String requestReturnUrl = HttpContext.Current.Request["ReturnUrl"];
if (requestReturnUrl != null && requestReturnUrl.IndexOf (":") != -1)
{
throw new SecurityException(SR.GetString(SR.Security_ReturnUrlCannotBeAbsolute, requestReturnUrl));
}
// GetRedirectUrl redirects to returnUrl if it exists, current app's default.aspx otherwise.
String redirectUrl = FormsAuthentication.GetRedirectUrl(userName, createPersistentCookie);
Debug.Assert (redirectUrl == requestReturnUrl || requestReturnUrl == null);
String updatedRedirectUrl = redirectUrl;
String cookieName = FormsAuthentication.FormsCookieName;
HttpCookie cookie = FormsAuthentication.GetAuthCookie(userName, createPersistentCookie, strCookiePath);
String strEncrypted = cookie.Value;
int ticketLoc = redirectUrl.IndexOf(cookieName + "=");
if(ticketLoc != -1)
{
updatedRedirectUrl = redirectUrl.Substring(0, ticketLoc);
updatedRedirectUrl += cookieName + "=" + strEncrypted;
int ampersandLoc = redirectUrl.IndexOf('&', ticketLoc);
if(ampersandLoc != -1)
{
updatedRedirectUrl += redirectUrl.Substring(ampersandLoc);
}
}
else
{
int loc = updatedRedirectUrl.IndexOf('?');
updatedRedirectUrl += (loc != -1) ? "&" : "?";
updatedRedirectUrl += cookieName + "=" + strEncrypted;
}
HttpContext.Current.Response.Redirect(updatedRedirectUrl, true);
// MobileRedirect.RedirectToUrl(HttpContext.Current, updatedRedirectUrl, true);
*/
}
///
public static void SignOut()
{
/*
MobilePage page = HttpContext.Current.Handler as MobilePage;
if (page != null)
{
page.Adapter.PersistCookielessData = false;
if (!page.Device.SupportsEmptyStringInCookieValue)
{
// Desktop signout with empty cookie value is not handled properly by the device.
InternalSignOut ();
return;
}
}
*/
FormsAuthentication.SignOut();
}
/*
private static void InternalSignOut ()
{
HttpContext context = HttpContext.Current;
String userName =
context.User == null || context.User.Identity == null || context.User.Identity.Name == null ?
"" :
context.User.Identity.Name;
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket (
1, // version
userName,
DateTime.Now, // Issue-Date
new DateTime(1999, 10, 12), // Expiration
false, // IsPersistent
"", // User-Data
FormsAuthentication.FormsCookiePath);
String encryptedTicket = FormsAuthentication.Encrypt (ticket);
if (encryptedTicket == null) { // Encrypt returned null
encryptedTicket = "x";
}
HttpCookie cookie = new HttpCookie (FormsAuthentication.FormsCookieName, encryptedTicket);
cookie.Path = FormsAuthentication.FormsCookiePath;
cookie.Expires = new System.DateTime (1999, 10, 12);
cookie.Secure = FormsAuthentication.RequireSSL;
context.Response.Cookies.Remove (FormsAuthentication.FormsCookieName);
context.Response.Cookies.Add (cookie);
}
*/
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
using System.Diagnostics;
using System.Security;
using System.Web.Security;
using System.Web.UI.MobileControls;
using System.Security.Permissions;
namespace System.Web.Mobile
{
/*
* MobileFormsAuthentication
* provides mobile comopatible version of ASP.Net methods
*
* Copyright (c) 2000 Microsoft Corporation
*/
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
public class MobileFormsAuthentication
{
// Class only contains statics, so make the constructor private.
private MobileFormsAuthentication()
{
}
///
public static void RedirectFromLoginPage(String userName, bool createPersistentCookie)
{
FormsAuthentication.RedirectFromLoginPage(userName, createPersistentCookie, FormsAuthentication.FormsCookiePath);
}
///
public static void RedirectFromLoginPage(String userName, bool createPersistentCookie, String strCookiePath)
{
FormsAuthentication.RedirectFromLoginPage(userName, createPersistentCookie, strCookiePath);
/*
// Disallow redirection to an absolute url.
String requestReturnUrl = HttpContext.Current.Request["ReturnUrl"];
if (requestReturnUrl != null && requestReturnUrl.IndexOf (":") != -1)
{
throw new SecurityException(SR.GetString(SR.Security_ReturnUrlCannotBeAbsolute, requestReturnUrl));
}
// GetRedirectUrl redirects to returnUrl if it exists, current app's default.aspx otherwise.
String redirectUrl = FormsAuthentication.GetRedirectUrl(userName, createPersistentCookie);
Debug.Assert (redirectUrl == requestReturnUrl || requestReturnUrl == null);
String updatedRedirectUrl = redirectUrl;
String cookieName = FormsAuthentication.FormsCookieName;
HttpCookie cookie = FormsAuthentication.GetAuthCookie(userName, createPersistentCookie, strCookiePath);
String strEncrypted = cookie.Value;
int ticketLoc = redirectUrl.IndexOf(cookieName + "=");
if(ticketLoc != -1)
{
updatedRedirectUrl = redirectUrl.Substring(0, ticketLoc);
updatedRedirectUrl += cookieName + "=" + strEncrypted;
int ampersandLoc = redirectUrl.IndexOf('&', ticketLoc);
if(ampersandLoc != -1)
{
updatedRedirectUrl += redirectUrl.Substring(ampersandLoc);
}
}
else
{
int loc = updatedRedirectUrl.IndexOf('?');
updatedRedirectUrl += (loc != -1) ? "&" : "?";
updatedRedirectUrl += cookieName + "=" + strEncrypted;
}
HttpContext.Current.Response.Redirect(updatedRedirectUrl, true);
// MobileRedirect.RedirectToUrl(HttpContext.Current, updatedRedirectUrl, true);
*/
}
///
public static void SignOut()
{
/*
MobilePage page = HttpContext.Current.Handler as MobilePage;
if (page != null)
{
page.Adapter.PersistCookielessData = false;
if (!page.Device.SupportsEmptyStringInCookieValue)
{
// Desktop signout with empty cookie value is not handled properly by the device.
InternalSignOut ();
return;
}
}
*/
FormsAuthentication.SignOut();
}
/*
private static void InternalSignOut ()
{
HttpContext context = HttpContext.Current;
String userName =
context.User == null || context.User.Identity == null || context.User.Identity.Name == null ?
"" :
context.User.Identity.Name;
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket (
1, // version
userName,
DateTime.Now, // Issue-Date
new DateTime(1999, 10, 12), // Expiration
false, // IsPersistent
"", // User-Data
FormsAuthentication.FormsCookiePath);
String encryptedTicket = FormsAuthentication.Encrypt (ticket);
if (encryptedTicket == null) { // Encrypt returned null
encryptedTicket = "x";
}
HttpCookie cookie = new HttpCookie (FormsAuthentication.FormsCookieName, encryptedTicket);
cookie.Path = FormsAuthentication.FormsCookiePath;
cookie.Expires = new System.DateTime (1999, 10, 12);
cookie.Secure = FormsAuthentication.RequireSSL;
context.Response.Cookies.Remove (FormsAuthentication.FormsCookieName);
context.Response.Cookies.Add (cookie);
}
*/
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XmlDomTextWriter.cs
- PrimitiveXmlSerializers.cs
- FormatSettings.cs
- ContainerParagraph.cs
- FontFamilyIdentifier.cs
- UdpDiscoveryEndpointProvider.cs
- SqlBulkCopy.cs
- MetafileEditor.cs
- TCPClient.cs
- PanelStyle.cs
- ChangeProcessor.cs
- Compensation.cs
- SpecularMaterial.cs
- EncryptedType.cs
- TextRange.cs
- PathHelper.cs
- XmlSchemaNotation.cs
- ApplicationProxyInternal.cs
- DoubleKeyFrameCollection.cs
- NavigationService.cs
- RenderContext.cs
- ExclusiveCanonicalizationTransform.cs
- ScopeElementCollection.cs
- Base64Stream.cs
- NumericUpDownAcceleration.cs
- RichTextBoxConstants.cs
- TableColumn.cs
- DefaultSection.cs
- XmlTypeMapping.cs
- CollectionChangeEventArgs.cs
- BitmapEffectDrawingContextWalker.cs
- GuidConverter.cs
- DBBindings.cs
- HostingPreferredMapPath.cs
- CodeMemberProperty.cs
- BreakRecordTable.cs
- ObjectDataSourceDisposingEventArgs.cs
- ComboBoxItem.cs
- StatusBarPanel.cs
- SingleSelectRootGridEntry.cs
- FileDialog.cs
- RedirectionProxy.cs
- ExecutionScope.cs
- ProtocolsConfigurationHandler.cs
- TextParaLineResult.cs
- InvalidProgramException.cs
- SelectionBorderGlyph.cs
- ImageAnimator.cs
- _SingleItemRequestCache.cs
- MetaTable.cs
- ExtenderControl.cs
- RotateTransform3D.cs
- ToolBarButtonClickEvent.cs
- HtmlInputPassword.cs
- WorkflowServiceHost.cs
- ModelPropertyCollectionImpl.cs
- SafePointer.cs
- InnerItemCollectionView.cs
- SymbolMethod.cs
- Table.cs
- TextLineBreak.cs
- Ops.cs
- FreezableDefaultValueFactory.cs
- SolidBrush.cs
- DataGridViewColumnCollection.cs
- MessageQueue.cs
- ObjectDataSourceView.cs
- DrawListViewSubItemEventArgs.cs
- TouchesOverProperty.cs
- SpecialTypeDataContract.cs
- ProcessThreadCollection.cs
- HelpProvider.cs
- WebControlsSection.cs
- UseLicense.cs
- GridViewColumnHeader.cs
- DesignerEditorPartChrome.cs
- OleDbInfoMessageEvent.cs
- DataServiceRequestOfT.cs
- TypeExtension.cs
- PageThemeCodeDomTreeGenerator.cs
- ConstNode.cs
- EncoderFallback.cs
- TypeSystemProvider.cs
- HyperLinkColumn.cs
- ProfileProvider.cs
- CircleEase.cs
- HostedTcpTransportManager.cs
- CodePropertyReferenceExpression.cs
- TextProperties.cs
- BamlResourceDeserializer.cs
- NetworkInterface.cs
- SettingsPropertyIsReadOnlyException.cs
- ErrorFormatter.cs
- DuplicateWaitObjectException.cs
- Tuple.cs
- NetworkCredential.cs
- BasePropertyDescriptor.cs
- XmlILConstructAnalyzer.cs
- PerCallInstanceContextProvider.cs
- Rectangle.cs