具有Windows身份验证和匿名WCF服务的Lightswitch服务器

时间:2014-06-20 11:47:25

标签: c# iis wcf-security visual-studio-lightswitch lightswitch-2013

我们已经为我们的内部网开发了一套带有lightswitch的应用程序。所有这些都使用Windows身份验证运行,但现在我们必须开发一些必须允许匿名连接的wcf服务(托管在LS应用程序中)。

这是我公开的服务的当前web.config设置:

<system.web>
  <authentication mode="Windows">
      <forms name="Main" />
  </authentication>
  <identity impersonate="true" />
</system.web>

<system.serviceModel>
   <services>
      <service behaviorConfiguration="metadataSupport" name="LightSwitchApplication.WCF.HelperService">
        <endpoint address="" binding="customBinding" bindingConfiguration="LightSwitchApplication.WCF.HelperService.customBinding0" contract="LightSwitchApplication.WCF.HelperService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
   </services>
   <bindings>
      <customBinding>
        <binding name="LightSwitchApplication.WCF.HelperService.customBinding0">
          <binaryMessageEncoding />
          <httpTransport authenticationScheme="Anonymous" />
        </binding>
      </customBinding>
    </bindings>
</system.serviceModel>

在这里挖掘到msdn后,我仍然没有找到是否有办法达到这种行为。

当我使用Windows凭据访问这些服务时,一切正常,我发现无法使用匿名身份验证服务。 我尝试更改绑定模式,将此装饰添加到我的服务中:

[ServiceContract(Namespace="")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[AllowAnonymous]
[SecurityPermission(SecurityAction.Assert)]
[OverrideAuthentication()]
[Authorize(Users="*")]
[OverrideAuthorization()]
public class HelperService
{
  ...
}

我还尝试在我的web.config中使用标记,并将我的WCF文件夹设置为主要文件夹下的应用程序,但在这种情况下问题是不同的,并且与compliation路径和dll目录有关路径。 我试图解决它:

<location path="WCF">
<system.web>
        <authentication mode="None" />
        <compilation>
            <codeSubDirectories>
                <add directoryName="../bin"/>
            </codeSubDirectories>
        </compilation>
</location>

但我仍然收到错误,因为IIS仍然找不到我的程序集: 无法加载文件或程序集'Microsoft.LightSwitch.Server,Version = 12.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一。系统找不到指定的文件。

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.LightSwitch.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.LightSwitch.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' could not be loaded.


=== Pre-bind state information ===
LOG: User = IIS APPPOOL\DefaultAppPool
LOG: DisplayName = Microsoft.LightSwitch.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///C:/inetpub/wwwroot/MyApp/WCF/
LOG: Initial PrivatePath = C:\inetpub\wwwroot\MyApp\WCF\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\inetpub\wwwroot\MyApp\WCF\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.LightSwitch.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/MyApp_wcf/88e6cc1b/e1821fec/Microsoft.LightSwitch.Server.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/MyApp_wcf/88e6cc1b/e1821fec/Microsoft.LightSwitch.Server/Microsoft.LightSwitch.Server.DLL.
LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/MyApp/WCF/bin/Microsoft.LightSwitch.Server.DLL.
LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/MyApp/WCF/bin/Microsoft.LightSwitch.Server/Microsoft.LightSwitch.Server.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/MyApp_wcf/88e6cc1b/e1821fec/Microsoft.LightSwitch.Server.EXE.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/MyApp_wcf/88e6cc1b/e1821fec/Microsoft.LightSwitch.Server/Microsoft.LightSwitch.Server.EXE.
LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/MyApp/WCF/bin/Microsoft.LightSwitch.Server.EXE.
LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/MyApp/WCF/bin/Microsoft.LightSwitch.Server/Microsoft.LightSwitch.Server.EXE.

好吧,不管这个......我将完整的bin文件夹从父文件夹复制到MyApp / wcf(仅用于测试,我稍后会解决),最后应用程序加载,但是...现在我得到401.2错误:

Error message 401.2.: Unauthorized: Logon failed due to server configuration.  Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server.  Contact the Web server's administrator for additional assistance.

我还在WCF文件夹中创建了一个web.config,允许以这种方式进行匿名访问:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <security>
            <authentication>
                <anonymousAuthentication enabled="true" />
                <windowsAuthentication enabled="false" />
            </authentication>
            <authorization>
                <add accessType="Allow" users="?" />
            </authorization>
        </security>
    </system.webServer>
    <system.web>
        <identity impersonate="false" />
    </system.web>
</configuration>

我需要帮助来解决它,因为它让我发疯。我想重用我们的LightSwitch应用程序中定义的所有业务逻辑,但我仍然不知道我是否能够做出如此“愚蠢的事情”

你能告诉我正确的方法吗?

非常感谢。

0 个答案:

没有答案
相关问题