本文介绍了web.config中的反斜杠出现两次的Visual Studio 2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的Visual Studio制作,直到我切换到2010年时VS所发生的,我开始看到我的数据库连接字符串一些奇怪的行为,2008年一切工作就好了一个asp.net web应用程序。的串(编辑,但格式是相同的)如下:

I have an asp.net web application that I made in Visual Studio 2008. Everything worked just fine until I switched to VS 2010. When that happened, I started seeing some weird behavior with my database connection string. The string (edited, but format is the same) is as follows:

<add name="DBname" connectionString="Data Source=SomeText\SomeMoreText;Initial Catalog=DB;Integrated Security=True" providerName="System.Data.SqlClient"/>

问题与SomeText \\ SomeMoreText一部分。结果
当我在调试器中运行这一点,'\\'改为'\\\\'。这打破了一切。

The problem is with the SomeText\SomeMoreText part.
When I run this in the debugger, the '\' is changed into '\\'. This breaks everything.

我的问题,这可能有一个非常简单的答案是这样的:
我怎样才能得到VS2010治疗连接字符串像一个正常的字符串,不试图插入额外的斜线?

My question, which probably has an extremely simple answer is this:How can I get VS2010 to treat the connection string like a normal string without trying to insert the extra slash?

推荐答案

额外的斜杠是不是有尽可能的字符串间pretation关注。它仅仅是斜线前一个转义字符'\\'\\'。

The extra slash is not there as far as interpretation of the string is concerned. It is merely an escape character '\' before the slash '\'.

要证据吗?以下添加到您的code(当然,适当的命名):

Want proof? Add the following to your code (with proper naming of course):

Debug.WriteLine(connectionStringValueHere);

下面是一个小的应用程序:

Here is a small app:

        string test = "This\\is\\a\\test";

        Console.WriteLine(test);
        Debug.WriteLine(test);

        Console.Read();

请注意,字符串,在这两个控制台和调试(输出窗口)为这\\是\\ A \\测试。如果您在做即时窗口下面时,code是在断点:

Note that the string, in both console and debug (output window) is This\is\a\test. If you do the following in the immediate window when the code is at a breakpoint:

 ? test

您看到下面的输出

? test
"This\\is\\a\\test"

但你有逃生present,这是正常的,在.NET中的字符串。

But you have the escapes present, which is normal for strings in .NET.

这篇关于web.config中的反斜杠出现两次的Visual Studio 2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 17:06