我有一个与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>