次の方法で共有


More playing with ASP.NET

As with my earlier messing around with a poll, I took a concept from the www.asp.net site today and made my own "CheckDotNet.aspx" page. The one on www.asp.net only checks for the .NET Framework 1.0 or better, so I modified the logic to detect 1.1 and 1.0 as two distinct cases... recommending an upgrade for no framework or 1.0, and returning "Framework Found" if you have 1.1 already.

<www.duncanmackenzie.net/tools/checkdotnet.aspx>

Difficult? Nope... nothing too impressive...

Useful? I have no idea, but I thought it was worth putting up. The page has only one bit of code, the load event handler (and yes, I know I could have overriden OnLoad... but the code I started with was using Page_Load, so I just went with it)...

      Sub Page_Load(sender as Object, e as EventArgs)
        Dim clrVersion as Version = Request.Browser.ClrVersion
        If clrVersion.Major > 0 Then
         If clrVersion.Minor > 0 Then
             aOkPanel11.Visible = True
         Else
             aOkPanel1.Visible = True
         End If
        Else
            downloadPanel.Visible = True
        End If
     End Sub

aOkPanel11 on my page contains the text to show if the user has the 1.1 version of the Framework... aOkPanel1 is shown if they have 1.0 only, and downloadPanel appears if they have no Framework at all.

Ouch... I guess I was porting/modifying that code way too quickly... goofed up the logic in a bunch of ways (thanks for the comments folks!)... at the risk of trying again and still screwing it up... here is another try at that routine;

     Sub Page_Load(sender as Object, e as EventArgs)
        Dim clrVersion as Version = Request.Browser.ClrVersion
        if clrVersion.Major = 1 Then
         if clrVersion.Minor > = 1 Then
             '1.1 or better, but less than 2.0
             aOkPanel11.Visible = true
         ElseIf clrVersion.Minor = 0 Then
             'only 1.0
             aOkPanel1.Visible = true
         end if
        elseif clrVersion.Major > 1 Then
            '2.x or greater... could have its own panel
            'but showing the 1.1 panel is probably the next
            'best thing...
            aOkPanel11.Visible = true
        else
            'anything else... should display for 
            '< 1.0 or nothing...
            downloadPanel.Visible = true
        end if
    
    end sub
 Also, in the html of the aOkPanel11, which can appear for the .NET Framework 1.1 or greater... I changed the text to reflect this possibility and added

<%Response.Write(Request.Browser.ClrVersion)%>

hopefully, this 'release' works better than the last one :)

Comments

  • Anonymous
    June 11, 2004
    You can just load the page in any browser other than IE, then it won't detect anything (unless you go into the pains and modify their user-Agent strings to include the .Net CLR version).
  • Anonymous
    June 11, 2004
    It will also report 1.1 if any higher version is installed on the machine. The code should be written to antipate future versions.
  • Anonymous
    June 12, 2004
    I know that there is no version over 1.1 but you should still add logic to check for this as there no doubt will be a higher version available. Probably when Whidbey ships or sooner.

    Regards Jens Peter Karlsen. Microsoft MVP - Frontpage.
  • Anonymous
    June 12, 2004
    Bill, it will actually report 1.0 if 2.0 (or any X.0) is installed. It's not a very good check.
  • Anonymous
    June 12, 2004
    How about:

    Dim clrVersion as Version = Request.Browser.ClrVersion

    if clrVersion.Major < 1 Then
    '< 1.0 or nothing...
    downloadPanel.Visible = true
    ElseIf clrVersion.Major = 1 And clrVersion.Minor < 1 Then
    ' 1.0
    aOkPanel1.Visible = true
    ElseIf clrVersion.Major = 1
    ' 1.x
    aOkPanel11.Visible = true
    Else
    ' 2+
    aOkPanel11.Visible = true
    EndIf

    Seems a little cleaner and easier to understand than your nested ifs version, especially when it's in VB (too many keywords expressin structure).