最佳读取web.config中的内容,方式 [英] Best way to read contents of web.config

查看:63
本文介绍了最佳读取web.config中的内容,方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要读取Web.Config中的内容,并通过电子邮件发送他们,有没有更好的方式来做到以下几点:

I need to read the contents of the Web.Config and send them off in an email, is there a better way to do the following:

        string webConfigContents = String.Empty;
        using (FileStream steam = new FileStream(
                 Server.MapPath("~/web.config"),
                 FileMode.Open, FileAccess.Read, FileShare.Read))
        {
            using (StreamReader reader = new StreamReader(steam))
            {
                webConfigContents = reader.ReadToEnd();
            }
        }

我不想锁定该文件。任何想法?

I dont want to lock the file. Any ideas?

编辑 - 我需要的文件的原始转储,我不能附加文件(虚拟主机提供商说,我的天!),和IM不找它里面具体的事情

推荐答案

您可以用此取代你的code:

You can replace your code with this:

string webConfigContents = File.ReadAllText(Server.MapPath("~/web.config"));

该文件将被锁定为写入而被读取,但不进行读取。但我不认为这将是一个问题,因为web.config文件通常不被写入(因为这将重新启动Web应用程序)。

The file will be locked for writing while it is being read, but not for reading. But I don't think this will be a problem, because the web.config file is not usually being written to (since this would restart the web application).

这篇关于最佳读取web.config中的内容,方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆