Forcing User.Identity to uppercase


J

jobs

Any way to force User.Identity to UpperCase after it's authenitcated?

Or if not, anybody got a good javascript snippet that would force
everything you type to upper?

Thanks.
 
Ad

Advertisements

G

Guest

Howdy,

1. Forcing User.Name to be upper cased:
Put follwing code into global.asax file:

void Application_PostAuthenticateRequest(object sender, EventArgs e)
{
HttpContext.Current.User = new MyPrincipal(
HttpContext.Current.User,
new MyIdentity(HttpContext.Current.User.Identity));
}

public class MyIdentity : System.Security.Principal.IIdentity
{
private readonly System.Security.Principal.IIdentity identity;

public MyIdentity(System.Security.Principal.IIdentity identity)
{
this.identity = identity;
}

public string AuthenticationType
{
get
{
return this.identity.AuthenticationType;
}
}

public bool IsAuthenticated
{
get
{
return this.identity.IsAuthenticated;
}
}

public string Name
{
get
{
string name = this.identity.Name;
return name == null ? null : name.ToUpper();
}
}
}

public class MyPrincipal : System.Security.Principal.IPrincipal
{
private readonly System.Security.Principal.IPrincipal principal;
private readonly System.Security.Principal.IIdentity identity;

public MyPrincipal(
System.Security.Principal.IPrincipal principal,
System.Security.Principal.IIdentity identity)
{
this.principal = principal;
this.identity = identity;
}

public System.Security.Principal.IIdentity Identity
{
get
{
return this.identity;
}
}

public bool IsInRole(string role)
{
return this.principal.IsInRole(role);
}
}

2. Forcing inputs to be uppercased:

<input type="text" style="text-transform: uppercase" />
<asp:TextBox runat="server" TextMode="SingleLine" ID="txt1"
Style="text-transform: uppercase" />
<asp:TextBox runat="server" TextMode="MultiLine" ID="txt2"
Style="text-transform: uppercase" />

hope this helps
 

Top