More in this section

Forums / Developing with Sitefinity / Get username from sitefinity to asp file

Get username from sitefinity to asp file

10 posts, 0 answered
  1. Pik Lee
    Pik Lee avatar
    142 posts
    Registered:
    13 Aug 2012
    06 Aug 2009
    Link to this post
    In the sitefinity page, I inserted an iframe. In the iframe, i placed a very simple asp page and trying to get the username from sitefinity after a user login. The asp page is a custom application I created. In regular asp, I can use <% response.form("username") %> to get the username. How does this work in sitefinity?

    Thanks,
    Pik

  2. Brian
    Brian avatar
    14 posts
    Registered:
    01 Dec 2007
    07 Aug 2009
    Link to this post
    you can get the current username by using the HTTPContext

    string username = HttpContext.Current.User.Identity.Name; 


    Im guessing you want to pass this to the iframe?  

    <iframe src="yourfile.asp?username=<%# HttpContext.Current.User.Identity.Name %>"></iframe>

    in your classic asp file, 
    <%= request.QueryString("username") %> 


    hope this works, just put it together.
  3. Pik Lee
    Pik Lee avatar
    142 posts
    Registered:
    13 Aug 2012
    07 Aug 2009
    Link to this post
    Brian,

    Thanks for the info. I inserted <iframe > tag in the "GenericContent", and it does not recognize "<%#". Any idea how to place "<%#" and "%>" in the src.

    Thanks.
  4. Brian
    Brian avatar
    14 posts
    Registered:
    01 Dec 2007
    07 Aug 2009
    Link to this post
    Im not sure if its going to be possible for you to add it to a Generic Content.

    You may have to make a user control that contains the <iframe> and place that on the page.

    Create a new file using your favorite editor, i used notepad.

    Add this to the file: 
    <iframe src="default.aspx?username=<%# HTTPContext.Current.User.Identity.Name %>"></iframe> 
    dont forget to change the target file.

    Save this with any file name you like, just make sure .ascx is the file extension.

    You can then login to siteifnity and upload this control for use.

    When editing a page, choose "Add Controls" , at the bottom there will be an "Upload Control" link.

    Just fill in the simple questions.  If it asks you to uplaod a codebehind file, click cancel.


    You should then be able to place this on your page and get your desired results.

  5. Pik Lee
    Pik Lee avatar
    142 posts
    Registered:
    13 Aug 2012
    07 Aug 2009
    Link to this post
    I am having problem to upload the file. It said " Access to the path 'c:\...\web.config" is denied. What changes do i need to make to the config file.

    Thanks.
  6. Pik Lee
    Pik Lee avatar
    142 posts
    Registered:
    13 Aug 2012
    07 Aug 2009
    Link to this post
    I've figured out. It is working now. Thank you for your help.
  7. Brian
    Brian avatar
    14 posts
    Registered:
    01 Dec 2007
    07 Aug 2009
    Link to this post
    Adding the control via the web.config file is also very easy.

    Open Web.Config

    Find the <toolboxControls>  tag.

    under that tag, you want to add something like this:
     <add name="Iframe Username" section="Iframe" url="~/UserControls/IframeTest.ascx" /> 

    dont forget to customize with where you have uploaded your file.

    The line above will add the control to a new section called "Iframe", if you expand that, you will see "Iframe Username" when editing a page.

    You can change either of those to your own preferences.






  8. Pik Lee
    Pik Lee avatar
    142 posts
    Registered:
    13 Aug 2012
    07 Aug 2009
    Link to this post
    When I open the page, I have the following message:

    CS0103: The name 'HttpContext' does not exist in the current context

    What am I missing here?

    Thanks.
  9. Brian
    Brian avatar
    14 posts
    Registered:
    01 Dec 2007
    07 Aug 2009
    Link to this post
    sorry, instead of 
    <%# HttpContext.Current.User.Identity.Name %> 

    try
    <%= HttpContext.Current.User.Identity.Name %> 

  10. Pik Lee
    Pik Lee avatar
    142 posts
    Registered:
    13 Aug 2012
    10 Aug 2009
    Link to this post
    Thank you.  It is working now.
Register for webinar
10 posts, 0 answered