Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • tarekahf 215 posts 153 karma points
    Mar 20, 2010 @ 14:29
    tarekahf
    0

    User Controls and Memeber Authentication.

     

    I am using Umbraco 4.0.3, Visual Studio 2005 + SP1, Windows Server 2003 R2.

    In this post, I will ask questions about User Controls and Authentication.

    User Controls:

    I've looked around how to implement User Controls in Umbraco, and I am trying to find the easiest and most suitable way.

    Here is the method I am following, and tell me if it is correct and if it will cause any problem in the future:

    1. Create a separate Web Application Project (WebProject) to host the User Controls (UC) as a Library .

    2. Create a solution with both Umbraco Website and WebProject in on VS Solution. If any other Class Libraries are required, just add them as Separate Project in same Solution. This is to save me from opening 2 or more instances of VS

    3. Create the UC in WebProject, say uc1.ascx, test it there, and using copy/past to copy the 3 files: uc1.ascx to a special folder under umbraco web site "..\usercontrols\MyControls" , and uc1.ascx.designer.vb, and uc1.ascx.vb to "..\app_code" under Umbraco.

    This way, I can start changing UC1.ascx in Umbraco Project directly.

    4. As alternate to step 3 above, I can copy the source .ascx only, and copy the result dll to the bin folder of Umbraco.

    With this method, every change I make, I have to copy the changes again to Umbraco. I think this is better approach. Right ?

    5. Create the Macro to link uc1.ascx to Umbraco and add it to a content page.

    I have tested the above methods, and they all work successfully.

    Question:

    1. Is the method above correct ?

    2. Is there a method to copy automatcially the changes made to UC1.ascx directly after compile of "WebProject", and copy them to Umbraco folders ?

    ============

    Authenitcation:

    I created a User Control to deal with Integrated Windows Authentication for Members. I created a Login.aspx Document using Umbraco back-office with the User Control embedded (via Macro) to implement this feature.

    So, to get the Currently logged-in Windows User ID (strUserID) I am using this method (inside Login.aspx/User Control/Page-Load):

    Note: This is a function in MyLib.GetWindowsLoginWeb() 

    Dim strUserID As String
    With System.Web.HttpContext.Current
    strUserID = .Request.ServerVariables("LOGON_USER")
    If strUserID = "" Then
      .Response.StatusCode = 401
      .Response.StatusDescription = "Unauthorized"
      .Response.End()
    Else
      Dim idx As Integer
      idx = strUserID.IndexOf("\")
      If idx >= 0 Then
        strUserID = strUserID.Substring(idx + 1)
      End if
    End if
    Return strUserID

     

     

     

     

    For the first time, if the IIS Request to some Umbraco Document (page), which is getting the Windows LOGON_USER, is not authenticated (Integrated Windows Authentication), the request will be transfered to "Login.aspx" with a correct ReturnUrl QueryString value, only and only if the page is not Protected using Umbraco back-office.

    But, for a Protected Page, and if the Request is not Authenticated as per Umbraco Members Membership Provider, it will be transfered to Login.aspx page, but there is no ReturnUrl Parameter ???? Instead, the URL " request.rawUrl() " will be the actual ReturnUrl.

    It seems to me that Umbraco 4.0.3 has some issue with regards FormsAuthentication and ReturnUrl. Right ?

    So, in order to deal with the above issue, I had to do exactly the following in Login.aspx Page, when the user click the "Login" button:   

     

    Protected Sub LoginButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

     

      Dim CurrUser As String

     

      Dim myRetURL As String

      CurrUser = MyLibrary.GetWindowsLoginIDWeb()

     

      FormsAuthentication.SetAuthCookie(CurrUser,

    True)

    myRetURL = Request.QueryString("ReturnUrl")

    If String.IsNullOrEmpty(myRetURL) Then

     

        If Page.Request.RawUrl().ToLower.IndexOf("Login.aspx".ToLower) < 0  Then

     

          myRetURL = Request.RawUrl

     

        Else

    ' User click login button after he open "Login.aspx" page directly

           myRetURL = FormsAuthentication.DefaultUrl()

     

        End if

      End if

      Response.Redirect(Page.ResolveClientUrl(HttpUtility.UrlEncode(myRetURL)), True)

    End Sub

    The above method works fine in both cases:

    1. If the request is not yet Authenticated from IIS under Intergrated Windows Authentication, and

    2. If the request is not authenticate for an Umbraco Protected Page.

    I just need to know if the above approach is correct.

    Am I missing something ?

    Is there a better method ?

    Tarek.

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Mar 20, 2010 @ 15:25
    Nik Wahlberg
    0

    Hi Tarek,

    I have not finished readiing your entire post as it deals with several topics (might be wise to split for easier searching and diving of experts to answer). But for your user controls, you can setup Post Build event in your VS to auto xcopy project files (dlls and ascx) to your Umbraco install. Here are the steps:

    1. Go to project properties
    2. Click on Build Events tab
    3. In postbuild event command line you should put something like this (replacing paths with your own, and adding any folders you have such as css, scripts, etc.):

    XCOPY "$(ProjectDir)bin\$(TargetName).*" "{Your Webroot Path}\bin" /Y
    XCOPY "$(ProjectDir)usercontrols\*.ascx" "{Your Webroot Path}\usercontrols" /Y

    As for your steps in section 1 I would recommend approach 4 as you stated over approach 3 as this more closely resembles a live deployment. 

    HTH,
    Nik

  • tarekahf 215 posts 153 karma points
    Mar 21, 2010 @ 07:25
    tarekahf
    0

    Nik,

    Thanks a lot. The post build events worked like a charm !

    I'm facing some difficulties dealing with this forums, and that is why I try avoid creating another post.

    I will split the second part to a new post.

    Tarek.

  • tarekahf 215 posts 153 karma points
    Mar 21, 2010 @ 07:54
    tarekahf
    0

    Regarding User Controls, I noticed that I can add the User Control directly from VS if I open the Umbraco Website from VS, and I can use them with Macros and insert them in Umbraco Documents as usual.

    Though it worked, but I am surprised why I never found any related Umbraco article telling you that this can be done ?

    All the articles I found telling that we must either create the related User Control DLL and copy it to the bin folder in Umbraco, or copy the related Code Files to Umbraco App_Code folder, and the source to the usercontrols directory.

    Appreciate your feedback.

    Tarek.

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Mar 21, 2010 @ 14:18
    Nik Wahlberg
    0

    Glad that worked out. I am sure it will save you a ton of time and the boring repetitive task of copying files manually. :) 

    On your other point, the process of creating your own DLLs and deploying them is more of a typical implementation (from what I do and have heard from others). This is a natural process if you have say a master project for any Umbraco implementation that you do. Check out this Wiki for generic project setups. In some cases it may make sense to have an overall development project, and smaller sub-projects to that when you need spcialized packaged functionality. 

    http://our.umbraco.org/wiki/how-tos/getting-started-with-umbraco-whats-next-after-you-install/setting-up-your-project-in-visual-studio

    Cheers,
    Nik

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies