开发者

IIS6 adding space to end of file path

开发者 https://www.devze.com 2023-02-03 00:35 出处:网络
string filePath = Properties.Settings.Default.audioFilePath.ToString() + \" \"; filePath = filePath.Replace(\" \", \"\");// iis6 on 2003 server seems to add a space to the end of the path
        string filePath = Properties.Settings.Default.audioFilePath.ToString() + " ";
        filePath = filePath.Replace(" ", "");           // iis6 on 2003 server seems to add a space to the end of the path
        string audioFilename = filePath + filename;
        return File(audioFilename, "audio/wav");

this is very puzzling to me. On my dev machine this works fine and the path is correct. On the production site my IIS6 adds a space to the filePath variable. I added the line to replace spaces with "" and even added the extra string on my local machine to make sure it was working.

I put a test view in place to pass the path to, on IIS6 I get:

c:\messages\voicemail\filed\ <

Notice the blank space between \filed\ and < (I added < so I can see the space)

On my dev machine I get

c:\__dev\_proj\msg\messages\<

I am swapping the path in the web.config file but there are no spaces, and anyway I'm removing spaces, but somewhere when it is served to the browser it seems IIS6 adds 开发者_StackOverflow中文版the space??? Tried different browsers too, IE and Firefox, both same result so it points to IIS????

Answer: trim was it, and the response that it wasn't a space was dead on. It was LF. the fixed code:

            string filePath = Properties.Settings.Default.audioFilePath;
        filePath = filePath.TrimEnd();           // iis6 on 2003 server seems to add a space to the end of the path
        string audioFilename = filePath + filename;


The problem sounds very unusual. But as a work around, rather than using Replace you should use Trim. And instead of filePath + fileName, try System.IO.Path.Combine(filePath, fileName). I don't know if this will suppress the symptoms or not, but it could be worth a shot.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号