【问题标题】:Cannot use multiple options OWIN不能使用多个选项 OWIN
【发布时间】:2015-02-17 05:11:00
【问题描述】:

我遇到了一个关于使用 OWIN 托管的服务器的小问题。我正在尝试使其可访问本地网络,这意味着我必须添加一些额外的选项:

// Start OWIN host 
        StartOptions options = new StartOptions();
        options.Urls.Add("http://localhost:4004");
        //options.Urls.Add("http://127.0.0.1:4004");
        //options.Urls.Add(string.Format("http://{0}:4004", Environment.MachineName));
        using (WebApp.Start<Startup>(options))
        {

            // Create HttpCient and make a request to api/values 
            HttpClient client = new HttpClient();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/text"));

        }

现在的问题是,如果我取消注释第二行:

options.Urls.Add("http://127.0.0.1:4004");

我会得到一个错误:

未处理的类型异常 mscorlib.dll 中发生“System.Reflection.TargetInvocationException”

附加信息:异常已被一个目标抛出 调用。

有人可以帮帮我吗?奇怪的是我只能使用localhost,而不是我的ip。

【问题讨论】:

  • 据此:stackoverflow.com/questions/16642651/… 您的代码看起来不错。异常中有更多细节吗?比如内部异常什么的。
  • @Mino 是的,有一个内部异常:“访问被拒绝”

标签: c# asp.net-web-api owin


【解决方案1】:

问题在于没有管理员权限。我得到一个访问被拒绝的内部异常。通过在清单应用程序文件中使用它,我使错误消失了:)

  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
  <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
    <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
  </requestedPrivileges>
</security>

【讨论】:

    猜你喜欢
    • 2019-04-25
    • 2021-11-04
    • 1970-01-01
    • 2018-10-03
    • 1970-01-01
    • 2013-04-10
    • 2017-03-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多