在IIS7.5上运行的ASP.Net Core RC1应用程序中使用User.Identity.Name

时间:2016-04-08 14:14:44

标签: iis iis-7.5 asp.net-core

我正在使用ASP.Net Core编写Intranet站点。我在VS2015中创建了该站点并选择使用Windows身份验证。我现在需要访问我的服务器代码中的当前用户帐户名。我对此很新,所以我错了,但我相信我应该使用User.Identity.Name?当我看到这个时,它是空的。我之前一直在使用自托管运行该网站,并且已经阅读了某个地方,如果您使用生成的web.cmd入口点,这是可以预期的,但在IIS下可以正常工作。我现在在IIS下运行它,但我看到了同样的行为。任何人都能指出我失踪的东西吗?

这是我的web.config文件:

<configuration>
  <system.webServer>
    <handlers>
      <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform processPath="..\approot\web.cmd" arguments="--server.urls http://address:5001" stdoutLogEnabled="true" stdoutLogFile="..\logs\stdout.log" startupTimeLimit="3600" forwardWindowsAuthToken="true"></httpPlatform>
  </system.webServer>
</configuration>

除了身份问题之外,使用此配置在IIS下运行正常。在ISS中,我使用从站点功能视图

访问的身份验证设置禁用了除站点的Windows身份验证之外的所有内容

如果需要,这是我的project.json文件的一部分,包含依赖项,命令和框架:

  "dependencies": {
    "Microsoft.AspNet.Diagnostics": "1.0.0-rc1-final",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.FileProviderExtensions" : "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final",
    "EntityFramework.Core": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    "EntityFramework.Commands": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer.Design": "7.0.0-rc1-final",
    "System.DirectoryServices.Linq": "1.2.2.1",
    "AutoMapper": "4.2.1"
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel",
    "ef" : "EntityFramework.Commands"

  },

  "frameworks": {
    "dnx451": {
        "dependencies": {
            "Services": "1.0.0-*"

        }
    }
  },

1 个答案:

答案 0 :(得分:0)

IISPlatformHandler模​​块中存在一个错误,需要您将应用程序的基本URL映射到虚拟目录(因为我理解解决方案,无论如何!!)。相当恼人的是,在发布问题之前我会遇到这个,但它似乎没有用。我只能假设我已经尝试了很多这样的东西,我第一次就把我的测试搞得一团糟。该网站现在在IIS

下完美运行

以下是您的启动类中要进行的代码更改:

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) {
            app.Map("/SomeBasePath", (app1) => this.ConfigureInternal(app1, env, loggerFactory));
        }

        public void ConfigureInternal(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)       {
             // your original call to Configure here
        }

因此,您基本上重命名原始的Configure方法,并从执行映射的新Configure方法中调用它。

假设您的网站之前以http://webserver:1234/Home运行。完成此更改后,您需要以http://webserver:1234/SomeBasePath/Home的形式访问它。这对我们的网站来说很好,所以如果你需要,我不知道如果没有网址中的额外节点你会怎么做。

相关问题