小编Gar*_*ama的帖子

在我的WCF Web服务中获取WindowsIdentity

我接管了一个不再和我们在一起的开发人员的代码.它是一个最初使用传入用户名的WCF Web服务,但我们需要它来使用WindowsIdentity.

string identity = ServiceSecurityContext.Current.WindowsIdentity.Name;
Run Code Online (Sandbox Code Playgroud)

该代码最终返回一个空字符串.我正在使用安全(wsHttpSecure)绑定,因此ServiceSecurityContext.Current不是null或任何东西.我一直在寻找一天的解决方案,但还没有找到任何东西.

因为我是WCF的新手,所以我不确定其他相关信息是什么.以下是IIS中Web服务的启用身份验证设置:

Anonymous Authentication - Enabled
Windows Authentication - Enabled
Run Code Online (Sandbox Code Playgroud)

这是web服务的web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <connectionStrings>
        <clear />
        <add name="LocalSqlServer" connectionString="Data Source=.\instanceNameHere;Initial Catalog=default;Integrated Security=SSPI;"/>
    </connectionStrings>
    <appSettings configSource="appSettings.config" />
    <system.diagnostics>
        <sources>
            <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
                <listeners>
                    <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\ServiceLogs\WebServiceLog.svclog" />
                </listeners>
            </source>
        </sources>
    </system.diagnostics>
    <system.web>
        <trace enabled="true" />
        <membership defaultProvider="XIMembershipProvider" userIsOnlineTimeWindow="30">
            <providers>
                <clear/>
                <add name="XIMembershipProvider" type="LolSoftware.MiddleTier.BusinessLogic.XIMembershipProvider"
      applicationName="LolWebService"/>
            </providers>
        </membership>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
        <client />
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
        <behaviors configSource="behaviors.config" /> …
Run Code Online (Sandbox Code Playgroud)

https wcf web-services windows-identity

4
推荐指数
1
解决办法
9712
查看次数

收集被修改; 枚举操作可能无法执行

我通过字典枚举并创建一个要添加到ListView的项目.但是,特别是一行导致此错误:

收集被修改; 枚举操作可能无法执行.

foreach (KeyValuePair<string, bool> s in test.Value.Properties)
{
    ListViewItem item = new ListViewItem();
    item.Text = String.Format("{0}", s.Key);
    if (s.Value) { item.Checked = true; } // the problem line
    listView2.Items.Add(item);
}
Run Code Online (Sandbox Code Playgroud)

我假设设置item.Text的原因是因为我没有修改原始值,因为它正在创建一个新字符串.如果我改变item.Checked = true来创建一个新的布尔值,它工作正常但布尔值总是默认为false,这不是我想要的.

我该如何解决这个问题?

另外,我是不是应该尝试修改foreach中的任何集合数据?我原本以为这个问题是因为我正在修改我正在循环的集合数据,但这似乎是ListViewItemCollection的一个问题,我没有循环遍历.

c# collections foreach

0
推荐指数
1
解决办法
598
查看次数

标签 统计

c# ×1

collections ×1

foreach ×1

https ×1

wcf ×1

web-services ×1

windows-identity ×1