Custom Server Control not working after uploaded

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sanjib65
    New Member
    • Nov 2009
    • 102

    Custom Server Control not working after uploaded

    I try to create a custom control that will say, Hello + ComputerUserNam e.

    I have added in my App_Code folder a WelcomeLabel.cs file:

    Code:
    // WelcomeLabel.cs 
    using System; 
    using System.ComponentModel; 
    using System.Security.Permissions; 
    using System.Web; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
     
    namespace Samples.AspNet.CS.Controls 
    { 
        [ 
        AspNetHostingPermission(SecurityAction.Demand, 
            Level = AspNetHostingPermissionLevel.Minimal), 
        AspNetHostingPermission(SecurityAction.InheritanceDemand, 
            Level = AspNetHostingPermissionLevel.Minimal), 
        DefaultProperty("Text"), 
        ToolboxData("<{0}:WelcomeLabel runat=\"server\"> </{0}:WelcomeLabel>") 
        ] 
        public class WelcomeLabel : WebControl 
        { 
            [ 
            Bindable(true), 
            Category("Appearance"), 
            DefaultValue(""), 
            Description("The welcome message text."), 
            Localizable(true) 
            ] 
            public virtual string Text 
            { 
                get 
                { 
                    string s = (string)ViewState["Text"]; 
                    return (s == null) ? String.Empty : s; 
                } 
                set 
                { 
                    ViewState["Text"] = value; 
                } 
            } 
     
            protected override void RenderContents(HtmlTextWriter writer) 
            { 
                writer.WriteEncodedText(Text); 
                if (Context != null) 
                { 
                    string s = Context.User.Identity.Name; 
                    if (s != null && s != String.Empty) 
                    { 
                        string[] split = s.Split('\\'); 
                        int n = split.Length - 1; 
                        if (split[n] != String.Empty) 
                        { 
                            writer.Write(", "); 
                            writer.Write(split[n]); 
                        } 
                    } 
                } 
                writer.Write("!"); 
            } 
        } 
    }
    And in my help.aspx Page directive I've added
    Code:
    <%@ Register TagPrefix="aspSample"  
            Namespace="Samples.AspNet.CS.Controls"%>
    While compiling in the local machine, it runs perfectly well and the Hello message comes with Computer User Name. But I've uploaded it to the Internet and opened up the page in my office computer but only Hello comes, the computer user name does not show up.
  • sanjib65
    New Member
    • Nov 2009
    • 102

    #2
    Does it by any chance relate to <authentication mode="Windows"> in web.config file?

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Check out this article:

      Hosting ASP.NET Applications in Medium Trust


      I think it might give you an idea about what's going on.

      -Frinny

      Comment

      Working...