Relative path from applicationsettings inside web.config
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>noreply@mydomain.com</value>
</setting>
</MyNamespace.MailLibrary.Properties.Settings>
</applicationSettings>
Everything works but I canno开发者_如何学Got 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?
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.
Try this:
<value>**~/_mail/MailTemplatesConfiguration.xml**</value>
Also, you may find the following link useful: http://msdn.microsoft.com/en-us/library/ms178116.aspx
精彩评论