如何在Visual Studio的配置文件中使用ip地址作为url? [英] How to use ip address as url in config file in visual studio?
本文介绍了如何在Visual Studio的配置文件中使用ip地址作为url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在配置文件中使用带有端口号的ip地址作为url值时,我收到以下错误
系统。 NotSupportedException:不支持给定路径' s格式
但是当我使用像http://www.google.com这样的网站时,这个工作正常。
我需要用什么才能做到这一点支持ip url格式...
我尝试过:
PFB是我试过的配置文件
<?xml version =1.0encoding = UTF-8 >?;
< configuration>
< appSettings>
< add key =baseURLvalue =https://192.168.0.33:6060/>
< / appSettings>
< / configuration>
解决方案
string fileTime = < span class =code-keyword> string .Format( {0:MM-dd-yyyy } {1} \\,startTime,BaseUrl.Replace( https:// , )。替换( http://, )。替换( www, )。替换( 。 , )。替换( com, )。ToUpper());
这样写这样的语句就是问题。
尝试使用WebConfigurationManager类。
见下面的代码片段
我的网络配置如下
< 配置 >
....
< appSettings >
< add 键 = PFUserName value = myusername / & gt;
< add key = PFPassWord value = mypassword / >
< / appSettings >
....
< / configuration >
读取它
string userName = WebConfigurationManager.AppSettings [ PFUserName]
When I use ip address with port number as url value in my config file I am getting the following error
System.NotSupportedException: The given path's format is not supported
But this is working fine when I use a website like "http://www.google.com"
What I have to use to make this ip url format supported...
What I have tried:
PFB is the config file I tried on
<?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="baseURL" value="https://192.168.0.33:6060" /> </appSettings> </configuration>
解决方案
string fileTime = string.Format("{0:MM-dd-yyyy} {1}\\", startTime, BaseUrl.Replace("https://", "").Replace("http://", "").Replace("www", "").Replace(".", "").Replace("com", "").ToUpper());
Writing statements like that is just asking for trouble.
Try using the WebConfigurationManager class.
see below snippet
my web config is as follows
<configuration> .... <appSettings> <add key="PFUserName" value="myusername"/> <add key="PFPassWord" value="mypassword"/> </appSettings> .... </configuration>
read it
string userName = WebConfigurationManager.AppSettings["PFUserName"]
这篇关于如何在Visual Studio的配置文件中使用ip地址作为url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文