OWIN 托管服务器问题:StartOptions WebApp.Start TargetInvocationException

我有一个与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”的异常

附加信息:调用的目标引发了异常。

 解决方法:

 

事实上问题在于缺少管理员权限。引起了一个被拒绝的内部异常。在清单应用程序文件中使用这个,错误消失了:)

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

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值