Archive for category VB.net

Uh Oh! Important: ASP.NET Security Vulnerability – ScottGu’s Blog

Important: ASP.NET Security Vulnerability – ScottGu’s Blog.

No Comments

Running vb.net alongside c# in a web app

via The ASP.NET Capsule #18: Running C# & VB.NET in the same web application – Jose R. Guay Paz.

Great snippet to wack in the web.config file, which allows you to run c# and vb.net code (*spit* :P ) in the same web project;


<system.codedom>
<compilers>

<compiler language="c#;cs;csharp" extension=".cs"  type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
     <providerOption name="CompilerVersion" value="v3.5" />
     <providerOption name="WarnAsError" value="false" />
</compiler>

<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
     <providerOption name="CompilerVersion" value="v3.5" />
     <providerOption name="OptionInfer" value="true" />
     <providerOption name="WarnAsError" value="false" />
</compiler>

</compilers>
</system.codedom>

No Comments

The provided URI scheme ‘http’ is invalid; expected ‘https

Going from dev to live, where the dev system referenced dev version of web services, but the live system has to reference live versions which are HTTPS i recieved this error;

The provided URI scheme ‘http’ is invalid; expected ‘https

This is resolved simply by updating the web.config file and setting the security tag’s mode attribute from None to Transport;

<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IWSHttpService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="None" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>

The provided URI scheme ‘http’ is invalid; expected ‘https.

8 Comments

Globalization “Current Culture” settings in the web.config (ASP.NET)

Quick example of the current culture switch in the web.config of a dot net project.

<configuration>
<
system.web>
<
globalization fileEncoding=”utf-8″ requestEncoding=”utf-8″ responseEncoding=”utf-8″ culture=”en-GB” uiCulture=”en-GB”/>
</
system.web>
</
configuration>

Globalization using ASP.NET.

2 Comments

Maintaining ViewState on Password fields

just found this little nugget over on DotNetSlackers.com - By default dot net will activly stop you from maintaining the value in password text boxes on post back- which can be a pain in the ass forcing your user to keep retyping their password (twice as you will almost certainly have a password confirm box!).  You can get round this using this beauty;

Protected Sub txtMyPasswordField_PreRender( ByVal sender As Object, ByVal e As System.EventArgs) Handles txtMyPasswordField.PreRender
    txtMyPasswordField.Attributes("value") = txtMyPasswordField.Text
End Sub

No Comments

2 tabs fresh!

In visual studio 2008 you'll notice a lot of operators such as foreach/ switch etc etc are listed as snippets in the intellisense menu, however when you hit tab to insert them it just autocompletes the keyword- if you hit tab twice it will insert the full snippet, giving you a dummy template usage for that keyword!

No Comments

VB to C# Code Converter

Just found a cool tool online for converting vb code to c#, and vice-versa.  It's not 100% perfect so make sure you have a look through what it turfs out, but it's handy for converting small code snippets of example functions you find online.  It's up on the DeveloperFusion website here.

No Comments

Google Code Highlighter

You may have noticed that the little snippets of code I’ve been dropping into these post’s suddenly got a bit swankier looking. This is down to a new javascript tool I found for use on blogs and the like, for highlighting code you post on your pages.

Basically you download the zip file- unzip it and copy the javascripts and css files over, then add a few lines of code to the head of your page;

You then put your code in-between >pre< tags and set a name attribute to “code” and set the class to whatever syntax you have- it has support for a whole bunch of languages including c#, vb, php, javascript, css, sql and a whole bunch of others. You can grab this plug-in from here

The install was easy- but a couple of bits did catch me out- the code sample above was the example they give you in the install page. So I blindly copied over this code to the head of my blog, and copied all the files from the zip file over to my sites js and css folders. I found that html highlighting worked fine and so did c# but vb and sql weren’t happening… It eventually clicked that you need to add the references to the additional syntax types you need as the example only has a line for the CS and XML/HTML “brush” libraries. So I popped those lines in and it worked fine.

The other problem that I had, and indeed still have until I get home to actually edit the code, is compatibility with TinyMCE which is the editor used by default in BlogEngine. I found a couple of articles which might help with this but won’t know till tonight;

As mentioned on the Wiki pages there is also the issue that adding a name value to a pre tag, isn’t valid xhtml.

No Comments

Using FindControl to find a repeater nested inside a repeater with HeaderTemplate or FooterTemplate defined

I just today cracked a problem which consumed my Friday afternoon and a big chunk of this morning.  This was something i hadn’t come across in .net when using repeaters before. 

On the aspx side I had a repeater embedded within a repeater;

  <asp:Repeater ID="rptAddedSeries" runat="server">
    <headerTemplate>
      <div id="seriesHeader">
    </headerTemplate>
    <itemTemplate>
      <h2>
        <%#Container.DataItem().Title%>
      </h2>
      <asp:Repeater ID="rptBooks" runat="server">
        <headerTemplate><ul></headerTemplate>
        <itemTemplate>
          <li>
            <%#Container.DataItem().BookID%>
          </li>
        </itemTemplate>
        <footerTemplate>
          </ul>
        </footerTemplate>
      </asp:Repeater>
    </itemTemplate>
    <footerTemplate>
      </div>
    </footerTemplate>
  </asp:Repeater>

I simply wanted to populate the inner repeater and perform the databinding.  The code i had worked fine- using FindControl to grab the inner repeater then setting the datasource and executeing DataBind().  However, when i added the HeaderTemplate and FooterTemplate to the parent “rptAddedSeries” control, the FindControl suddenly stopp working and i started getting a NullReferenceException when trying to set my DataSource.

Protected Sub rptAddedSeries_ItemDataBound(ByVal sender As Object,  ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs)Handles rptAddedSeries.ItemDataBound
   Dim this_repeater_item As RepeaterItem = DirectCast(sender, Repeater).Controls.Item(_repeater_counter)
   Dim child_repeater As Repeater = DirectCast(this_repeater_item.FindControl("rptBooks"), Repeater)
   child_repeater.DataSource = _highlight.Highlights_Seriess(_repeater_counter).Highlight_Series_Books 
   child_repeater.DataBind() 
   _repeater_counter += 1
End Sub

After a bit of googling I found a forum post on asp.net forums by someone with a similar issue.  The ItemDataBound event occurs against each part of the your repeater item- meaning if you have a HeaderTemplate and FooterTemplate as well as your standard ItemTemplate, the ItemDataBound will execute 3 times.  So I added a condition at the start of the function to ensure that i was running my code only during the ItemTemplate data binding;

If e.Item.ItemType = ListItemType.Item Then
  ...  
End If

However i was still having issue’s with the FindControl failing.  Reading down the same forum post i found a note mentioning that FindControl wouldn’t work directly against the RepeaterItem but there was nothing to say whatI should be running it against.  Considering the it was the e (RepeaterItemEventArgs) object we tested to find the current ItemType, it stood to reason that the actual item might be contained within there so i modified the method and it worked perfectly;

Protected Sub rptAddedSeries_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptAddedSeries.ItemDataBound
  If e.Item.ItemType = ListItemType.Item Then
    'Dim this_repeater_item As RepeaterItem = DirectCast(sender, Repeater).Controls.Item(_repeater_counter)
    'Dim child_repeater As Repeater = DirectCast(this_repeater_item.FindControl("rptBooks"), Repeater) 
    'Dim child_repeater As Repeater = DirectCast(this_repeater_item.TemplateControl.FindControl("rptBooks"), Repeater)

    Dim child_repeater As Repeater = DirectCast(e.Item.FindControl("rptBooks"), Repeater) 
    child_repeater.DataSource = _highlight.Highlights_Seriess(_repeater_counter).Highlight_Series_Books 
    child_repeater.DataBind() 
    _repeater_counter += 1 
  End If 
End Sub

Hope this save’s someone else a few hours of tearing their hair out!

1 Comment