简体   繁体   中英

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

My 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.

Does anyone know how to make it so?

I think this will help.

1) web.config:

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

Aspx page:

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

Don't forget to add System.Configuration in references.

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.

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 %>' . You're telling the application to lookup the configuration section appSettings and the key value autoemail .

I realise it's a little late to help you now, but it may help others in the future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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