Codecoding

.NET Technology

Asp.net

Customizing the packages folder in NuGet

Maybe you’re trying to change the location of the packages folder where all the stuff gets installed using the NuGet Package Manager in Visual Studio. There’s a handy solution that will work: You have to place a new config file called nuget.config wherever you want in your folder structure. There, you will have to put this piece of code: <settings> <repositoryPath>myfolder\packages</repositoryPath> </settings> The path is always relative to the nuget.config‘s ubication so, in this example, it will look for a folder named myfolder just in the directory...Read more ->

Asp.net

Error when sending mail on .NET 4

Recently I upgraded one of our web applications from .NET 3.5 to 4 and surprisingly I started to get some weird errors whenever the application tried to send emails. If you suddenly get errors like this one and recently upgraded your application to .NET 4 surely it will be caused by the same error: Failure sending mail. Inner Exception: Index was outside the bounds of the array. EXCEPTION TYPE: IndexOutOfRangeException at System.Net.Base64Stream.EncodeBytes(Byte[] buffer, Int32 offset, Int32 count, Boolean dontDeferFinalBytes, Boolean shouldAppendSpaceToCRLF) at System.Net.Base64Stream.Write(Byte[]...Read more ->

Asp.net

How to render a <label for=”"> tag using asp.net

Just a quick hack for everyone of you which are wondering how to get a well formed tag using asp.net. It turns out that our beloved Label control can render as a span or as a label. All you have to do to change its behaviour is to fill the Label property AssociatedControlID with the id of the control you want to bind. That’s it! Read more ->

Silverlight

Enable Silverlight debugging in firefox

Tim Heuer leaves us this super useful gem of wisdom. Worth reading it as you may one day struggle with it: Read more ->

Asp.net

Trying to get ClientID property from a programmatically added control

Recently I had to face the following scenario: I was trying to create a customized gridview which automatically loaded an also customized template for the pager that fully integrated with some custom object that I was receiving from an external library. In short, I needed to generate some controls in a dynamic way and decorate them with client capabilities. I thought that using the clientID will do the trick but I was surprised by the fact that when you add some control to your page/control you cannot get the proper clientID property until PreRender event of the page/control life cycle. So if...Read more ->

Asp.net

JQuery 1.5 for Visual Studio.

If you’re looking for VSDoc in order to use with JQuery 1.5 you can get it from here. Enjoy! Read more ->

Miscellanea

Unable to use saved credentials to log on to a remote computer in Windows Vista

If you have Windows Vista installed on your system and you need to frequently connect to another computers via remote desktop maybe you suffer the problem I am about to tell. Probably you mark the checkbox telling that you want windows to remember your credentials but whenever you try to connect again, here we go, Windows Vista wants you to input your credentials one more time and you receive the following message: Your credentials did not work. Your system administrator does not allow the use of saved credentials to log on to the remote computer because its identity is not fully verified. Please...Read more ->

Silverlight

Silverlight Security

I will leave you here a very cool article by Microsoft about security in Silverlight and WCF. Worth reading it. Read more ->

Asp.net

Lambda Expressions: inner workings

This is an old post explaining all the inner workings of lambda expressions in VB but it’s still interesting if you want to understand how to work with them: http://msdn.microsoft.com/en-us/magazine/cc163362.aspx Read more ->

Asp.net

Panel’s defaultButton property and linkButtons not working in Firefox

Recently I changed all the buttons of the website I am developing right now for linkButtons. I was searching for some hover behaviour cross-browser compatibility. As you may know, the greatest web depeloper’s friend, a.k.a. Internet Explorer 6, does not support the hover CSS pseudo-class but in<a> tags. And this is a shame because all the hover effects in buttons will never work in IE6 unless you do the old javascript image source trick, and we don’t want to use it because we love CSS and, besides that, the user experience is better without that old javascript. So, that’s...See the code ->

Maybe you’re trying to change the location of the packages folder where all the stuff gets installed using the NuGet Package Manager in Visual Studio.

There’s a handy solution that will work: You have to place a new config file called nuget.config wherever you want in your folder structure. There, you will have to put this piece of code:

<settings>
	<repositoryPath>myfolder\packages</repositoryPath>
</settings>

The path is always relative to the nuget.config‘s ubication so, in this example, it will look for a folder named myfolder just in the directory where nuget.config is placed.

As you can see in the following folder structure it will place the packages folder under myfolder.

myfolder
    packages
    myfolder2
       packages
nuget.config

Consequently, if you put :

<settings>
	<repositoryPath>myfolder\myfolder2\packages</repositoryPath>
</settings>

It will search under myfolder2.

More information here.

Roberto ADD COMMENTS

Recently I upgraded one of our web applications from .NET 3.5 to 4 and surprisingly I started to get some weird errors whenever the application tried to send emails.

If you suddenly get errors like this one and recently upgraded your application to .NET 4 surely it will be caused by the same error:

Failure sending mail.

Inner Exception:
Index was outside the bounds of the array.

EXCEPTION TYPE: IndexOutOfRangeException
at System.Net.Base64Stream.EncodeBytes(Byte[] buffer, Int32 offset, Int32 count, Boolean dontDeferFinalBytes, Boolean shouldAppendSpaceToCRLF)
at System.Net.Base64Stream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.Mime.MimePart.Send(BaseWriter writer)
at System.Net.Mime.MimeMultiPart.Send(BaseWriter writer)
at System.Net.Mail.Message.Send(BaseWriter writer, Boolean sendEnvelop
Stak Trace: at System.Net.Mail.SmtpClient.Send(MailMessage message)
at Web_Utilities.Utils.Mail.SendMail(MailMessage mail)
at System.Net.Base64Stream.EncodeBytes(Byte[] buffer, Int32 offset, Int32 count, Boolean dontDeferFinalBytes, Boolean shouldAppendSpaceToCRLF)
at System.Net.Base64Stream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.Mime.MimePart.Send(BaseWriter writer)
at System.Net.Mime.MimeMultiPart.Send(BaseWriter writer)
at System.Net.Mail.Message.Send(BaseWriter writer, Boolean sendEnvelope)
at System.Net.Mail.SmtpClient.Send(MailMessage message)

It seems that there’s a bug in .NET 4 related to sending emails sized more than 3 MB.

Hopefully it can be fixed using a MS hotfix that you can find here.

Take into consideration that when you apply the hotfix it won’t require any server reboot but your ASP.NET state service will stop. Just restart it and do an IIS reset just to be sure that everything will run ok as on one of my node servers the hotfix didn’t work until I reset the IIS.

Roberto ADD COMMENTS

Just a quick hack for everyone of you which are wondering how to get a well formed tag using asp.net. It turns out that our beloved Label control can render as a span or as a label.

All you have to do to change its behaviour is to fill the Label property AssociatedControlID with the id of the control you want to bind.

That’s it!

Roberto ADD COMMENTS

Tim Heuer leaves us this super useful gem of wisdom. Worth reading it as you may one day struggle with it:

Roberto ADD COMMENTS

Recently I had to face the following scenario: I was trying to create a customized gridview which automatically loaded an also customized template for the pager that fully integrated with some custom object that I was receiving from an external library.

In short, I needed to generate some controls in a dynamic way and decorate them with client capabilities. I thought that using the clientID will do the trick but I was surprised by the fact that when you add some control to your page/control you cannot get the proper clientID property until PreRender event of the page/control life cycle.

So if one of your added controls need to make reference to another one in a generated client script you better get sure that you’re retrieving the clientID on the PreRender event of this control.

I will post you an example to better explain all this:

'we create some controls
Dim bt as New Button With {.ID="bt"}
Dim slider as New Panel With {.ID="slider"}

'and then we add it to the page or control
'in this case I'm creating a Template
'so I'm creating them into the InstantiateIn method of the ITemplate
'container makes reference to the control where this template resides.
container.Controls.Add(bt)
container.Controls.Add(slider)

'now we want to create some client script code involving this two controls
'if we do this now it won't work.
'Our clientID will be just "bt", not "ContentPlaceHolder1_gw_bt" as it would be expected
'if this control was added to a gridview in a page using a MasterPage
_grid.Page.ClientScript.RegisterStartupScript _
(Me.GetType,"script",String.Format("$('#{0}').click();", bt.ClientID),True)

'to get this working you can do this:
AddHandler slider.Prerender, _
Sub (o As Object, e As EventArgs)
     _grid.Page.ClientScript.RegisterStartupScript(Me.GetType,"script", _
     String.Format("$('#{0}').click();", bt.ClientID),True)
End Sub

'This way the client script will be resolved on PreRender I will be able to get the real clientID of the generated controls.

Roberto ADD COMMENTS

If you’re looking for VSDoc in order to use with JQuery 1.5 you can get it from here.

Enjoy!

Roberto ADD COMMENTS

If you have Windows Vista installed on your system and you need to frequently connect to another computers via remote desktop maybe you suffer the problem I am about to tell. Probably you mark the checkbox telling that you want windows to remember your credentials but whenever you try to connect again, here we go, Windows Vista wants you to input your credentials one more time and you receive the following message:

Your credentials did not work. Your system administrator does not allow the use of saved credentials to log on to the remote computer because its identity is not fully verified. Please enter new credentials.

This can be a real pain if your passwords are like mine: dT045Gfx_a!odl … Remembering more than 2 of these is not really comfortable.

As I suffered this problem too I want to redirect you to the correct solution by the hand of Computer Troubleshooters:

  1. Log on to your computer as an administrator.
  2. Click Start/Run
  3. Type gpedit.msc
  4. Go to Computer Configuration\Administrative Templates\System\Credentials Delegation
  5. Double-click on Allow Delegating Saved Credentials with NTLM-only Server Authentication
  6. Check Enable and then click on the Show button
  7. Add “TERMSRV/” to the server list, then your domain, example: TERMSRV/mydomain.com. You can use one wildcard (*) in a name. For example to enable the setting on all servers in “mydomain.com” type “TERMSRV/*.mydomain.com” or for all servers use: TERMSRV/*
  8. Confirm the changes by clicking on OK until you return back to the main Group Policy Object Editor dialog.
  9. At a command prompt, run gpupdate to force the policy to be refreshed immediately on the local machine or restart the computer

Roberto ADD COMMENTS

I will leave you here a very cool article by Microsoft about security in Silverlight and WCF. Worth reading it.

Roberto ADD COMMENTS

This is an old post explaining all the inner workings of lambda expressions in VB but it’s still interesting if you want to understand how to work with them:

http://msdn.microsoft.com/en-us/magazine/cc163362.aspx

Roberto ADD COMMENTS

Recently I changed all the buttons of the website I am developing right now for linkButtons. I was searching for some hover behaviour cross-browser compatibility. As you may know, the greatest web depeloper’s friend, a.k.a. Internet Explorer 6, does not support the hover CSS pseudo-class but in<a> tags. And this is a shame because all the hover effects in buttons will never work in IE6 unless you do the old javascript image source trick, and we don’t want to use it because we love CSS and, besides that, the user experience is better without that old javascript.

So, that’s it, then we need to change all buttons and imageButtons for linkButtons, that’s all. Unfortunately, this is not such an easy thing if you have panels which implement the defaultButton property. If you use IE6 or any of its younger brothers you will not notice anything but if you dare -oh poor boy!- to use Firefox then you will surely notice that your beloved defaultButton property does not work at all!!

What’s happening here?

Basically, we got a javascript issue in here. Whenever you have a panel implementing default button you got this thing rendered in your HTML:

<div id="panelClientId" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'idOfyourButton')">
</div>

and this is the WebForm_FireDefaultButton function:

function WebForm_FireDefaultButton(event, target) {
    if (event.keyCode == 13 && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea"))) {
        var defaultButton;
        if (__nonMSDOMBrowser) {
            defaultButton = document.getElementById(target);
        }
        else {
            defaultButton = document.all[target];
        }
        if (defaultButton && typeof(defaultButton.click) != "undefined") {
            defaultButton.click();
            event.cancelBubble = true;
            if (event.stopPropagation) event.stopPropagation();
            return false;
        }
    }
    return true;
}

The problem here is that click attribute only exists in Internet Explorer. You can try this at home by copying this html below to a blank html file and run it in Internet Explorer and Firefox. As you will see, the click attribute is only set in IE.

<a onclick="javascript:alert('hello world');return false;" id="lnk" href="http://www.codecoding.com">hello</a>
<script type="text/javascript">
	var o=document.getElementById('lnk');
	alert(o.click);
	alert(o.onclick);
	try{
		o.click();
	}catch(e){
		alert("click? what's this");
	}
	o.onclick();
</script>

Maybe the problem should be solved by correctly implementing the WebForm_FireDefaultButton by the asp.net team but we will try another approach: we are going to implement a new class extending the linkButton behaviour to generate this click attribute when it gets rendered and then do a tag mapping for all the linkbutton classes in our project.

See the code ->

Roberto 1 COMMENT

About Me

Welcome to my blog!! If you need to contact me, please email me at code@codecoding.com

Subscribe here