Thursday, February 10, 2011

capture windows username in asp.net mvc request

i have an intranet app asp.net mvc site. is there anyway to capture the windows nt login from the user wihtout having a full login system in the site. i dont want permissioning but i would like to do some logging on the server to track requests, etc . .

  • If you set IIS to use Windows Authentication and the site is in the Intranet Zone for your clients then the logins will automatically happen without any prompts at all.

    From blowdart
  • What version of Windows is this mvc app running on?

    You could try the following:

    • Use IIS Manager to disable anonymous access to the site, and make sure digest and/or windows authentication is enabled.
    • Change the mvc app's web.config to use Windows Authentication
    • Access the login name in the controller using User.Identity.Name.

    Would that do?

    From IanT8
  • You can use HttpContext.Current.User.Identity.Name if you set up the site to use Windows Authentication. Many browsers will pass the username on transparently.

    ooo : it seems with firefox, it prompts for a user name / pwd even though IE seems to not require it . . any ideas on why this is happenning
    ooo : Dan Diplo - any ideas ?
    Dan Diplo : FireFox, by default, doesn't pass on the username. However, it can be made to work - see http://markmonica.com/2007/11/20/firefox-and-integrated-windows-authentication/
    From Dan Diplo

NSString converting percentage characters

Hi,

I have an NSString *str = @"T%B3%C3%83";

where %C3 represents A with an umlut (I think), %B3 an m, %83 a superscript 3...

What is the best way to convert these percentages into the actual characters.

Thanks.

  • use -stringByReplacingPercentEscapesUsingEncoding method in NSString.
    P.S. However I don't know what encoding you must use to get results you've mentioned in your question (are you sure they're correct?)

    From Vladimir

decoding base64 encoded string with URL escaped characters

I am currently working on importing contacts from windows live contacts(hotmail addressbook). At one stage, the service posts back some data that i need to my page as a base64 encoded string which, as per microsoft documentation, contains url escaped sequences for '&' and '='. The string is thus not standard base64 encoded. The problem is when I try to convert it back to the original string from coldfusion, coldfusion refuses to recognize this as a valid base64 encoded string. How can I obtain the original string?

string looks something like this: "eact%253D28grLAdrSYSMp6mYbAozFuDqlgk78UZZ%25252F5A%25252Bygx.... (pretty long)" My cfmethod to convert back is simple - tostring(tobinary("ENCODED STRING"))// Thanks to Ben nadel The error obtained is "parameter 1 of tobinary which is is not base64 encoded"

Please help...

How to change the tabbar color in vaadin?

Hi want to change the tab color when the tab get focus in vaadin?can any one help me how to customize tabsheet to achive this..

  • It's a good idea to use a tool like firebug to inspect the DOM structure of the components. For example, when inspecting the DOM structure of the TabSheet example in the Sample, you will see that all tab has the style class v-tabsheet-tabitem. If you select the first tab, it will get the following style class "v-tabsheet-tabitemcell", "v-tabsheet-tabitemcell-first" and "v-tabsheet-tabitemcell-selected-first". If you select the second tab, it will get the following style classes: "v-tabsheet-tabitemcell" and "v-tabsheet-tabitemcell-selected". As you will see, the styles you need to modify are a bit dependent on the tab's position in the tabsheet.

    About changing the color of the tab, let's take a look at the selected tab's css.

    
    .v-tabsheet-tabitemcell-selected {
       background-image:url(common/img/vertical-sprites.png);
       background-position:left -1444px;
    }
    
    

    As you can see, the actual css is not complicated. The technique used in the css is however a not so common, it uses a sort of optimization. All the background images are joined in one single png image and the background image's position is adjusted so that we get the image we want to show as the background. What you need to do, is to create your own theme and modify that image to suite your own needs. Check the Book of Vaadin for more details about creating custom themes.

    From Kim L
  • Actually, you do not need to know the technique (CSS sprites) in order to change the background of the tabs. You will only need to use regular CSS, no magic involved.

    So create a new background image (of a solid color is not enough) and set that to the background of the relevant element. Repeat for all relevant elements that are contained in the tab (they might also specify some background).

    If you wish to modify the original images from the Vaadin Reindeer theme, they can be found from here: http://dev.vaadin.com/browser/versions/6.4/WebContent/VAADIN/themes/reindeer/tabsheet/img

    From Jouni

Stripping MS Word Tags Using Html Agility Pack

Hi Everyone,

I have a DB with some text fields pasted from MS Word, and I'm having trouble to strip just the , and tags, but obviously keeping their innerText.

I've tried using the HAP but I'm not going in the right direction..

Public Function StripHtml(ByVal html As String, ByVal allowHarmlessTags As Boolean) As String
    Dim htmlDoc As New HtmlDocument()
    htmlDoc.LoadHtml(html)
    Dim invalidNodes As HtmlNodeCollection = htmlDoc.DocumentNode.SelectNodes("//div|//font|//span")
    For Each node In invalidNodes
        node.ParentNode.RemoveChild(node, False)
    Next
    Return htmlDoc.DocumentNode.WriteTo()
End Function

This code simply selects the desired elements and removes them... but not keeping their inner text..

Thanks in advance

  • Well... I think I found a solution:

    Public Function StripHtml(ByVal html As String) As String
        Dim htmlDoc As New HtmlDocument()
        htmlDoc.LoadHtml(html)
        Dim invalidNodes As HtmlNodeCollection = htmlDoc.DocumentNode.SelectNodes("//div|//font|//span|//p")
        For Each node In invalidNodes
            node.ParentNode.RemoveChild(node, True)
        Next
        Return htmlDoc.DocumentNode.WriteContentTo
    End Function
    

    I was almost there... :P

    From gjsduarte

Global Variable not incrementing on callback functions

i am using Webclient to upload data using Async call to a server,

    WebClient webClient = new WebClient();
   webClient.UploadDataAsync(uri , "PUT", buffer, userToken);

i've attached DatauploadProgress and DatauploadCompleted Events to appropriate callback functions

        // Upload Date Completed 
        webClient.UploadDataCompleted += new
                UploadDataCompletedEventHandler(UploadDataCallback2);

        // Upload Date Progress
        webClient.UploadProgressChanged += new 
                 UploadProgressChangedEventHandler(UploadProgressCallback);

and in the functions i am trying to show some MessageBoxes:

      // Upload Date Progress
     void UploadProgressCallback(object sender, UploadProgressChangedEventArgs e)
    {
        MessageBox.Show( this,"Upload Progress  ,x =" +x);
        x++;
        MessageBox.Show(e.BytesSent.ToString());
    }



        // Upload Date Completed 
     void UploadDataCallback2(object sender, UploadDataCompletedEventArgs e)
    {

        MessageBox.Show(this, "Upload Done,x =" +x);
        x++;
        MessageBox.Show(ASCIIEncoding.UTF8.GetString(e.Result));
    }

Where x is a global variable, However for some reason x is not getting incremented, and all the message boxes show x=0..

any explanation would be much appreciated..

  • Oh found the problem, well apparently the problem was a 2-parts problem , and i hope someone would confirm my conclusion :

  • the MessageBox.show on the progress, blocked the function from progressing resulting in x staying at zero until i pressed ok.
  • The files i was uploading were too small, so the datauploadcompleted event was called before i got enough time to click the ok on the messagebox from the progress event
  • Rubens Farias : seems right to me; replace that messabe by `"Upload Progress ,x =" + ++x` and try to upload a larger file to confirm
    Madi D. : Yep, after editing the "messabe" ;) to ++x , and with a bigger file i solved the problem, thamks Rubens :)
    Eclipsed4utoo : The `MessageBox` is a dialog box that stops the execution of the code until it is dismissed.
    From Madi D.

Expecting identifier before object string :(

Hi, I'm trying to format this line correctly but so far, I'm getting no where:

NSString *urlAddress = selectedCell.@"html";

selectedCell is the category chosen,

IBOutlet UILabel *selectedCellText;
NSString *selectedCell;

How do I sort this out?

  • Fixed it,

    NSString *urlAddress = [[NSBundle mainBundle] pathForResource:selectedCell ofType:@"htm"];
    
    From Shamil