简体   繁体   English

如何使用asp web.config变量作为链接

[英]How do use asp web.config variable as link

Hi i'm working on a link inside a asp:login and I want to add a "variable" from the web config instead of hard coding the link directly inside the aspx. 嗨,我正在asp:login内的链接上工作,我想从Web配置中添加“变量”,而不是直接在aspx内对链接进行硬编码。

 <asp:login
        ID="seamenLogin" runat="server" 
        Inloggning med <a class='linkbutton' href='https:// (BankID, Mobil BankID, ...)</a><br/><br/><br/>
</asp:login>

My web.config: 我的web.config:

  <appSettings>
    <add key="autoemail" value="someone@somedomain.com" />
  </appSettings>

I want the text "someone@somedomain.com" to be a link inside the login aspx. 我希望文本“ someone@somedomain.com”成为登录aspx内的链接。

Does anyone know how to make it so? 有人知道怎么做吗?

I think this will help. 我认为这会有所帮助。

1) web.config: 1) web.config:

<appSettings>
    <add key="autoemail" value="someone@somedomain.com"/>
  </appSettings>

Aspx page: Aspx页面:

 <a href="mailto:<%=ConfigurationManager.AppSettings["autoemail"]%>">Link</a>

Don't forget to add System.Configuration in references. 不要忘记在引用中添加System.Configuration。

This is a bit of an old thread, but, perhaps the best way is to code the value directly into the control that you're working with. 这是一个旧线程,但是,最好的方法可能是将值直接编码到您正在使用的控件中。

The easiest way to do this is to use the configuration specifier code block <%$ %> . 最简单的方法是使用配置说明代码块<%$ %> You see this when you set-up a data connection stored in the connection strings section of your web.config file. 设置存储在web.config文件的连接字符串部分中的数据连接时,您会看到此消息。

Here's an example based on what you've specified above... 这是一个基于您上面指定的示例...

<asp:login ID="seamenLogin" runat="server">
    Inloggning med
    <a class='linkbutton' href='<%$ appSettings:autoemail %>'>(BankID, Mobil BankID, ...)</a>
    <br/><br/><br/>
</asp:login>

Notice the href='<%$ appSettings:MyLoginLink %>' . 请注意href='<%$ appSettings:MyLoginLink %>' You're telling the application to lookup the configuration section appSettings and the key value autoemail . 您要告诉应用程序查找配置部分appSettings和键值autoemail

I realise it's a little late to help you now, but it may help others in the future. 我知道现在为您提供帮助有点晚了,但是将来可能会帮助其他人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM