问题描述:

Using this code I made to simplify my problem:

<%@ Page Language="c#" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>

<HEAD>

<title>Am I me</title>

<script language="c#" runat="server">

private void Page_Load(object sender, System.EventArgs e) {

Label2.Text = "I am " + HttpContext.Current.User.Identity.Name;

bool result = Context.User.IsInRole(HttpContext.Current.User.Identity.Name);

Label1.Text = "Am I me? " + result;

result = HttpContext.Current.User.IsInRole(HttpContext.Current.User.Identity.Name);

Label1.Text += " Am I myself now? " + result;

}

</script>

</HEAD>

<body>

<form id="Form1" runat="server">

<div>

<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>

</div>

<div>

<asp:Label id="Label1" runat="server" Width="100%" Height="280px"></asp:Label>

</div>

</form>

</body>

</HTML>

When I runs this code locally it works fine:

But when I run it on our IIS server:

Does anyone have any idea what is going on?

I am using windows-authentiation on intranet sites to clarify. Also the usernames on both match.

网友答案:

You are asking if the user is in a Windows group that happens to have the same name as the user.

From the Microsoft documentation for IsInRole:

Determines whether the current principal belongs to the Windows user group with the specified name.

I suspect the reason it works on your local machine is that you happen to have a group with the same name as your user and your user is also a member of this group.

相关阅读:
Top