从同一解决方案中的单独类库中访问Web.Config [英] Access Web.Config from a seperate Class Library in same Solution

查看:49
本文介绍了从同一解决方案中的单独类库中访问Web.Config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个层次结构:


+解决方案

|

| --- +类库项目

| |

| | --- LogError.vb

|

| --- + ASP .NET Web应用程序

|

| --- Web.config


我想从Web.config访问:


< appSettings>

< add key =" sqlConnString"来自LogError.vb的$ = $ b< / appSettings>


.value =" myDBString">
有人知道我会怎么做吗?

So I have this hierarchy:

+ Solution
|
|--- + Class Library Project
| |
| |--- LogError.vb
|
|--- + ASP .NET Web Application
|
|--- Web.config

I want to access from Web.config:

<appSettings>
<add key="sqlConnString" value="myDBString">
</appSettings>

from LogError.vb. Anyone know how I would go about doing this?

推荐答案

首先,我的理解是这种事情不是允许。


其次,我很好奇你为什么要这样做。


最后,web.config只是一个文本文件如果你需要阅读内容,你就可以这样对待它。但;不要期望使用web.config文件配置您的

类库项目。创建一个新的配置文件

或者,使用machine.config文件

" bradtm" <峰; br **** @ discussions.microsoft.com>在消息中写道

新闻:79 ********************************** @ microsof t.com ...
First of all, it is my understanding that this sort of thing is not allowed.

Second, I am curious on why you want to do this.

Lastly, the web.config is just a text file and you can treat it as such if
you just need to read the contents. But; don''t expect to configure your
class library project using the web.config file. Create a new config file
Or, use the machine.config file
"bradtm" <br****@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
所以我有这个层次结构:

+解决方案
|
| --- +类库项目 | |
| | --- LogError.vb
|
| --- + ASP .NET Web应用程序
|
| --- Web.config

我想从Web.config访问:

< appSettings>
< add key =" sqlConnString"来自LogError.vb的value =" myDBString">
< / appSettings>

有人知道我会怎么做吗?
So I have this hierarchy:

+ Solution
|
|--- + Class Library Project
| |
| |--- LogError.vb
|
|--- + ASP .NET Web Application
|
|--- Web.config

I want to access from Web.config:

<appSettings>
<add key="sqlConnString" value="myDBString">
</appSettings>

from LogError.vb. Anyone know how I would go about doing this?



嗨布拉德。

如果你想阅读二进制web.config文件你将需要使用

Server.MapPath方法。

Dim reader As New System.IO.StreamReader(Server.MapPath(" web。) config"))

Dim value As String = reader.ReadToEnd


如果你想读取web.config部分内的值appSettings只是

使用ConfigurationSetting命名空间


Dim sqlConStr As String =

ConfigurationSettings.AppSettings(" sqlConnString")

--------------------------

Jean-Claude Morin,MCP

软件开发商

2k1Soft / kCentric,Canada

" bradtm" <峰; br **** @ discussions.microsoft.com>在消息中写道

新闻:79 ********************************** @ microsof t.com ...
Hi Brad.
If you want to read the binary web.config file you will need to use the
Server.MapPath methods.

Dim reader As New System.IO.StreamReader(Server.MapPath("web.config" ))
Dim value As String = reader.ReadToEnd

If you want to read the value inside the web.config section appSettings just
use the ConfigurationSetting namespace

Dim sqlConStr As String =
ConfigurationSettings.AppSettings("sqlConnString")
--------------------------
Jean-Claude Morin, MCP
Software Developer
2k1Soft/kCentric, Canada
"bradtm" <br****@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
所以我有这个层次结构:

+解决方案
|
| --- +类库项目 | |
| | --- LogError.vb
|
| --- + ASP .NET Web应用程序
|
| --- Web.config

我想从Web.config访问:

< appSettings>
< add key =" sqlConnString"来自LogError.vb的value =" myDBString">
< / appSettings>

有人知道我会怎么做吗?
So I have this hierarchy:

+ Solution
|
|--- + Class Library Project
| |
| |--- LogError.vb
|
|--- + ASP .NET Web Application
|
|--- Web.config

I want to access from Web.config:

<appSettings>
<add key="sqlConnString" value="myDBString">
</appSettings>

from LogError.vb. Anyone know how I would go about doing this?



我构建了一个应用程序来记录和查看我们的所有错误和错误

应用程序有。我们在许多

应用程序中使用了一个通用的类库项目。 LogError函数位于其中一个类库中。在

命令存储错误的应用程序ID我需要访问Web.config文件中的

应用程序ID键。


Tampa.NET Koder写道:
I built an Application to log and view all the errors and bugs our
applications have. We use a common Class Library Project in many of our
applications. The LogError function is in one of these Class Libraries. In
order to store the Application ID of the error I need to access the
Application ID key in the Web.config file.

"Tampa.NET Koder" wrote:
首先,我的理解是不允许这种事情。

其次,我很好奇你为什么要这样做最后,web.config只是一个文本文件,你可以这样处理它,如果你只需要阅读内容。但;不要期望使用web.config文件配置您的类库项目。创建一个新的配置文件
或者,使用machine.config文件
bradtm <峰; br **** @ discussions.microsoft.com>在消息中写道
新闻:79 ********************************** @ microsof t.com。 ..
First of all, it is my understanding that this sort of thing is not allowed.

Second, I am curious on why you want to do this.

Lastly, the web.config is just a text file and you can treat it as such if
you just need to read the contents. But; don''t expect to configure your
class library project using the web.config file. Create a new config file
Or, use the machine.config file
"bradtm" <br****@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
所以我有这个层次结构:

+解决方案
|
| --- +类库项目
| |
| | --- LogError.vb
|
| --- + ASP .NET Web应用程序
|
| --- Web.config

我想从Web.config访问:

< appSettings>
< add key =" sqlConnString"来自LogError.vb的value =" myDBString">
< / appSettings>

有人知道我会怎么做吗?
So I have this hierarchy:

+ Solution
|
|--- + Class Library Project
| |
| |--- LogError.vb
|
|--- + ASP .NET Web Application
|
|--- Web.config

I want to access from Web.config:

<appSettings>
<add key="sqlConnString" value="myDBString">
</appSettings>

from LogError.vb. Anyone know how I would go about doing this?




这篇关于从同一解决方案中的单独类库中访问Web.Config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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