web.config 中 applicationsettings 的相对路径
我有一个 DLL,它为 asp.net 应用程序提供邮件发送功能,该 DLL 从 xml 文件读取其配置,该文件的路径在 app.config 设置中设置。
我将配置移植到 web.config 内的 applicationsettings 部分:
<applicationSettings>
<MyNamespace.MailLibrary.Properties.Settings>
<setting name="MailTemplatesConfigurationPath" serializeAs="String">
<value>**./_mail/MailTemplatesConfiguration.xml**</value>
</setting>
<setting name="SenderAddress" serializeAs="String">
<value>[email protected]</value>
</setting>
</MyNamespace.MailLibrary.Properties.Settings>
</applicationSettings>
一切正常,但我找不到指定相对于 webapp 根的路径的方法,MailTemplatesConfigurationPath
值始终相对于 IIS 根,因此:
./_mail/MailTemplatesConfiguration.xml
变成
c:\windows\system32\inetsrv\_mail\MailTemplatesConfiguration.xml
有没有办法引用网站的根路径?
I have a DLL that provides mail sending functionality to an asp.net application, this DLL reads its configuration from an xml file whose path is set in an app.config setting.
I ported the configuration into an applicationsettings section inside my web.config:
<applicationSettings>
<MyNamespace.MailLibrary.Properties.Settings>
<setting name="MailTemplatesConfigurationPath" serializeAs="String">
<value>**./_mail/MailTemplatesConfiguration.xml**</value>
</setting>
<setting name="SenderAddress" serializeAs="String">
<value>[email protected]</value>
</setting>
</MyNamespace.MailLibrary.Properties.Settings>
</applicationSettings>
Everything works but I cannot find a way to specify a path relative to the webapp root, MailTemplatesConfigurationPath
value is always relative to IIS root, so:
./_mail/MailTemplatesConfiguration.xml
becomes
c:\windows\system32\inetsrv\_mail\MailTemplatesConfiguration.xml
Is there any way to reference the root path of the web site?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的问题是您不希望 dll 中存在 server.MapPath,请让使用此值的函数接受 rootPath 的另一个参数,该参数可以从调用代码传入。不在dll中的调用代码可以使用MapPath来获取rootPath值。
If your issue is that you don't want server.MapPath in the dll, have the function that uses this value accept another parameter for the rootPath which can be passed in from the calling code. The calling code, which is not in the dll, can use MapPath to get the rootPath value.
试试这个:
此外,您可能会发现以下链接很有用:
http://msdn.microsoft.com/en-us/library/ms178116.aspx
Try this:
Also, you may find the following link useful:
http://msdn.microsoft.com/en-us/library/ms178116.aspx