Forcing User.Identity to uppercase

Discussion in 'ASP .Net' started by jobs, Nov 17, 2007.

  1. jobs

    jobs Guest

    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.
     
    jobs, Nov 17, 2007
    #1
    1. Advertisements

  2. jobs

    Guest 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
     
    Guest, Nov 17, 2007
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.