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:
And in my help.aspx Page directive I've added
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.
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("!");
}
}
}
Code:
<%@ Register TagPrefix="aspSample"
Namespace="Samples.AspNet.CS.Controls"%>
Comment