How to write an URI string in App.Config

前端 未结 3 579
终归单人心
终归单人心 2021-02-06 22:35

I am making a Windows Service. The Service has to donwload something every night, and therefor I want to place the URI in the App.Config in case I late

3条回答
  •  我在风中等你
    2021-02-06 23:20

    You haven't properly encoded the ampersands in your URI. Remember that app.config is an XML file, so you must conform to XML's requirements for escaping (e.g. & should be &, < should be < and > should be >).

    In your case, it should look like this:

    
        
    
    

    But in general, if you wanted to store a string that looked like "I <3 angle bra>>" then do this:

    
        
    
    
    void StringEncodingTest() {
        String expected = "I <3 angle bra>>";
        String actual   = ConfigurationManager.AppSettings["someString"];
        Debug.Assert.AreEqual( expected, actual );
    }
    

提交回复
热议问题