1

I am trying to follow this Tutorial
Tutorial Link

When I start a New Project in VS 2019 ver 16.7.5 Net Framework 4.8 using ASP.NET Web Forms Application. I do not see a Default.aspx page in the project. Because this looks like a HTML page to me I tried to add the code from the tutorial to an HTML container. Lots of errors ?
I am converting the C# code to VB.

My question is do I need to be adding a Library ?
Or how do I add a Default.aspx form to the project?

Solution Explorer NOW
Solution Explorer

Vector
  • 3,066
  • 5
  • 27
  • 54
  • if you created a Web Forms project, that should be enough to create a `default.aspx` file – Daniel A. White Jan 09 '22 at 20:39
  • @DanielA.White I would agree but after a lot of reading and 5 failed New Project creations I do not see any Default.aspx page in the project looking at this link https://www.howtosolutions.net/2021/11/visual-studio-missing-asp-net-web-application-template-dotnet-framework/ – Vector Jan 09 '22 at 20:42
  • @DanielA.White The link looks like a solution but I am being forced by VS to update which I do not want to do in order to download or search for the net Framework 4.8 SDK Do you think Net Framewrok 4.72 SDK will work ? – Vector Jan 09 '22 at 21:13
  • Try the following: Close the solution. Backup/copy the solution folder. In the solution folder, delete the `.vs` folder. Then open the solution. It may take a minute while the .vs folder is recreated. Then right-click `default.aspx`. Select `View Designer`. Right-click `default.aspx`. Select `View Code Gen File`. – Tu deschizi eu inchid Jan 11 '22 at 17:35

1 Answers1

3

Ensure that you have the correct VS Workloads and Individual Components installed.

  • Open Visual Studio Installer
  • Click Modify
  • Click Workloads tab
  • Ensure ASP.NET and web development is checked, if not, check it.
  • Click Individual components
  • Check desired .NET Framework SDK's and targeting pack (ie: .NET Framework 4.7.2 SDK, .NET Framework 4.7.2 targeting pack, .NET Framework 4.8 SDK, and .NET Framework 4.8 targeting pack)
  • If you made any changes, in lower-right corner, select Download all, then install. Then click Modify.

Then try the following:

Note: The code below is converted to VB.NET from here. However, the class name was changed. For testing, I used .NET Framework version 4.8, but other versions may work.

VS 2019:

Create a new project

  • Open Visual Studio

  • Click Continue without code

  • Click File

  • Select New

  • Select Project

  • Select the following:

    enter image description here

  • Then, select:

    enter image description here

  • Click Next

  • Enter desired project name (ex: RSSFeedReader)

  • Click Create

  • Select the following:

    enter image description here

  • Optional: On right-side, under Advanced, uncheck Configure for HTTPS

  • Click Create

Open Solution Explorer

  • In VS menu, click View
  • Select Solution Explorer

Add class (name: RSSFeed.vb)

  • In Solution Explorer, right-click <project name> (ex: RSSFeedReader)
  • Select Add
  • Select Class... (name: RSSFeed.vb)
  • Click Add

RSSFeed.vb

Public Class RSSFeed
    Public Property Title As String
    Public Property Link As String
    Public Property PublishDate As String
    Public Property Description As String
End Class

Add WebForm (name: default.aspx)

  • In Solution Explorer, right-click <project name> (ex: RSSFeedReader)
  • Select Add
  • Select New Item...
  • Select Web Form (name: default.aspx)
  • Click Add

Modify default.aspx

  • In Solution Explorer, right-click default.aspx
  • Select View Markup

default.aspx:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="default.aspx.vb" Inherits="RSSFeedReader._default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <h3>Read RSS Feeds</h3>

        <form id="Form1" runat="server" >

            <!-- Where XYZ refers to the publication from where you wish to fetch the RSS feed from -->
            <div style="max-height:350px; overflow:auto">
                <asp:GridView ID="gvRss" runat="server" AutoGenerateColumns="false" ShowHeader="false" Width="90%">
                    <Columns>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <table width="100%" border="0" cellpadding="0" cellspacing="5">
                                    <tr>
                                        <td>
                                            <h3 style="color:#3E7CFF"><%#Eval("Title") %></h3>
                                        </td>
                                        <td width="200px">
                                            <%#Eval("PublishDate") %>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <hr />
                                            <%#Eval("Description") %>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td> </td>
                                        <td align="right">
                                            <a href='<%#Eval("Link") %>' target="_blank">Read More...</a>
                                        </td>
                                    </tr>
                                </table>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </div>    
        </form>
    </body>
</html>

Modify default.aspx.vb

  • In Solution Explorer, right-click default.aspx
  • Select View Code

default.aspx.vb:

Public Class _default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'ToDo: replace with the URL to your desired RSS feed
        Dim rssFeedUrls As List(Of String) = New List(Of String)()

        'add desired URLs
        rssFeedUrls.Add("https://www.nasa.gov/rss/dyn/lg_image_of_the_day.rss")
        rssFeedUrls.Add("http://thehill.com/rss/syndicator/19110")

        'get data
        PopulateRssFeed(rssFeedUrls)
    End Sub

    Private Sub PopulateRssFeed(rssFeedUrls As List(Of String))
        'create new List
        Dim feeds As List(Of RSSFeed) = New List(Of RSSFeed)
        Dim currentURL As String = String.Empty

        Try
            For Each url As String In rssFeedUrls

                'set value
                currentURL = url

                'create new instance
                Dim xDoc As XDocument = New XDocument()

                'load
                xDoc = XDocument.Load(url)

                Dim items = From x In xDoc.Descendants("item")
                            Select New RSSFeed With
                            {
                                .Title = x.Element("title").Value,
                                .Link = x.Element("link").Value,
                                .PublishDate = x.Element("pubDate").Value,
                                .Description = x.Element("description").Value
                            }

                If items IsNot Nothing Then
                    For Each i In items
                        Dim f As RSSFeed = New RSSFeed() With {
                            .Title = i.Title,
                            .Link = i.Link,
                            .PublishDate = i.PublishDate,
                            .Description = i.Description
                            }

                        'add 
                        feeds.Add(f)
                    Next
                End If
            Next

            gvRss.DataSource = feeds
            gvRss.DataBind()
        Catch ex As Exception
            'ToDo: replace with desired code
            Dim errMsg As String = String.Format("Error (PopulateRssFeed): {0} (url: {1})", ex.Message, currentURL)
            Debug.WriteLine(errMsg)
            Throw ex
        End Try
    End Sub
End Class

Ensure the following IIS features are installed/turned on: (Win 7)

  • Open Control Panel

  • Select View by: Small icons

  • Click Programs and Features

  • On left side click Turn Windows features on or off

    enter image description here

  • Expand Internet Information Services

  • Expand Web Management Tools

  • Check IIS Mangement Console

    enter image description here

  • Expand World Wide Web Services

  • Expand Application Development Features

  • Check ASP.NET (checking this option will also check some other options)

    enter image description here

  • Click OK


Update:

_default is defined in "default.aspx.designer.vb"

To open default.aspx.designer.vb:

  • In Solution Explorer, right-click default.aspx
  • Select View Code Gen File

default.aspx.designer.vb

'------------------------------------------------------------------------------
' <auto-generated>
'     This code was generated by a tool.
'
'     Changes to this file may cause incorrect behavior and will be lost if
'     the code is regenerated. 
' </auto-generated>
'------------------------------------------------------------------------------

Option Strict On
Option Explicit On


Partial Public Class _default

    '''<summary>
    '''Form1 control.
    '''</summary>
    '''<remarks>
    '''Auto-generated field.
    '''To modify move field declaration from designer file to code-behind file.
    '''</remarks>
    Protected WithEvents Form1 As Global.System.Web.UI.HtmlControls.HtmlForm

    '''<summary>
    '''gvRss control.
    '''</summary>
    '''<remarks>
    '''Auto-generated field.
    '''To modify move field declaration from designer file to code-behind file.
    '''</remarks>
    Protected WithEvents gvRss As Global.System.Web.UI.WebControls.GridView
End Class

Update 2:

When creating the project, for "Create a new ASP.NET Web Application" if you choose:

enter image description here

then use the following code in "Default.aspx" instead of the code above:

Default.aspx:

<%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="RSSFeedReader._Default" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">

    <h3>Read RSS Feeds</h3>
        <!-- Where XYZ refers to the publication from where you wish to fetch the RSS feed from -->
        <div style="max-height:350px; overflow:auto">
        <asp:GridView ID="gvRss" runat="server" AutoGenerateColumns="false" ShowHeader="false" Width="90%">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <table width="100%" border="0" cellpadding="0" cellspacing="5">
                            <tr>
                                <td>
                                    <h3 style="color:#3E7CFF"><%#Eval("Title") %></h3>
                                </td>
                                <td width="200px">
                                    <%#Eval("PublishDate") %>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <hr />
                                    <%#Eval("Description") %>
                                </td>
                            </tr>
                            <tr>
                            <td> </td>
                                <td align="right">
                                    <a href='<%#Eval("Link") %>' target="_blank">Read More...</a>
                                </td>
                            </tr>
                        </table>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </div>    
</asp:Content>

Note: The code for "Default.aspx.vb" is the same.


Update 3:

According to this video, if you want to view a YT RSS feed, you need to use the following for the URL: https://www.youtube.com/feeds/videos.xml?channel_id=<channel_id>

Note: The <channel_id> is the last portion of the URL (ie: after the last /). According to the video, there is a limit of 15 entries.

Also, one needs to use namespaces for the XML. Therefore, use the following for "default.aspx.vb":

default.aspx.vb:

Public Class _default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'ToDo: replace with the URL to your desired RSS feed
        Dim rssFeedUrls As List(Of String) = New List(Of String)()

        'add desired URLs
        rssFeedUrls.Add("https://www.youtube.com/feeds/videos.xml?channel_id=UCBB7sYb14uBtk8UqSQYc9-w")

        'get data
        PopulateRssFeedYT(rssFeedUrls)
    End Sub

    Private Sub PopulateRssFeedYT(rssFeedUrls As List(Of String))
        'create new List
        Dim feeds As List(Of RSSFeed) = New List(Of RSSFeed)
        Dim currentURL As String = String.Empty

        Try
            For Each url As String In rssFeedUrls

                'set value
                currentURL = url

                'create new instance
                Dim xDoc As XDocument = New XDocument()

                'load
                xDoc = XDocument.Load(url)

                Dim items = From x In xDoc.Descendants("{http://www.w3.org/2005/Atom}entry")
                            Select New RSSFeed With
                            {
                             .Title = x.Element("{http://www.w3.org/2005/Atom}title").Value,
                             .Link = x.Element("{http://www.w3.org/2005/Atom}link").Attribute("href").Value,
                             .PublishDate = x.Element("{http://www.w3.org/2005/Atom}published").Value,
                             .Description = x.Element("{http://search.yahoo.com/mrss/}group").Element("{http://search.yahoo.com/mrss/}description").Value
                            }

                If items IsNot Nothing Then
                    For Each i In items
                        Dim f As RSSFeed = New RSSFeed() With {
                            .Title = i.Title,
                            .Link = i.Link,
                            .PublishDate = i.PublishDate
                        }

                        If i.Description.Length <= 50 Then
                            f.Description = i.Description
                        Else
                            'only show the first 50 chars
                            f.Description = i.Description.Substring(0, 50)
                        End If

                        'add 
                        feeds.Add(f)
                    Next
                End If
            Next

            gvRss.DataSource = feeds
            gvRss.DataBind()
        Catch ex As Exception
            'ToDo: replace with desired code
            Dim errMsg As String = String.Format("Error (PopulateRssFeed): {0} (url: {1})", ex.Message, currentURL)
            Debug.WriteLine(errMsg)
            Throw ex
        End Try
    End Sub
End Class

Note: For alternative methods of retrieving the desired data the following may be helpful:

Resources:

Tu deschizi eu inchid
  • 4,117
  • 3
  • 13
  • 24
  • I am sure your answer is correct and greatly appreciate the amount of time and detail provided I am trying to install the Net Framework Developer Pak 4.8 even though the only item missing when I search is NET Framework 4.8 SDK Side note when I try to open Visual Studio Installer It is trying to force an update to 16.11.8 I am trying NOT to do this I found the Net Framework Developer Pak 4.8 as a down load but if downloaded will it install to VS 2019 ver 16.7.5 ? – Vector Jan 10 '22 at 06:29
  • I am on Windows 7 64 bit Pro if that matters – Vector Jan 10 '22 at 06:50
  • I edited the question with the steps I could complete and the process I used the BIG issue is not finding AspNet Web App (Net Framework) – Vector Jan 10 '22 at 07:40
  • @Vector: When you open Visual Studio Installer, if there is an update available, there will be an "Update" button. If you don't want to update, then don't click that button. To add/modify Workloads/Individual Components installed on your current version, click the "Modify" button. – Tu deschizi eu inchid Jan 10 '22 at 15:38
  • The .NET Framework Developer Packs (SDK) can be found [here](https://dotnet.microsoft.com/en-us/download/visual-studio-sdks). After installing the SDK, you can open Visual Studio Installer, click "Modify", go to "Individual Components", and then see if it shows up there and has a check mark next to it. – Tu deschizi eu inchid Jan 10 '22 at 15:56
  • Posted the ERROR I am getting in an EDIT to the Question Will try to debug not sure I know what is going on though – Vector Jan 10 '22 at 19:01
  • Trying to create the Empty Template Not finding that little icon anywhere – Vector Jan 10 '22 at 19:53
  • Here are the errors the app created Default.aspx I did not Still trying Thanks posted in the Question – Vector Jan 10 '22 at 20:39
  • Looks like there was an extra `Click Next` in the instructions, I've fixed it. Please try again. Ensure that you select `Visual Basic` , `Windows`, `Web` or `Visual Basic` , `All platforms`, `Web` – Tu deschizi eu inchid Jan 10 '22 at 20:45
  • The following may be helpful: [How to: Locate and organize project and item templates](https://learn.microsoft.com/en-us/visualstudio/ide/how-to-locate-and-organize-project-and-item-templates?view=vs-2019) – Tu deschizi eu inchid Jan 10 '22 at 21:18
  • It runs with no Errors but this is all I see on the localhost web page still lost

    Read RSS Feed from "NASA"

    and not happy with this line of code widthunderlined in green
    – Vector Jan 10 '22 at 21:48
  • back to this ERROR Could not load type 'RSSFeedReader._default'. I had the wrong line of code in Defult.aspx top most line ALSO because this is not my code I notice we do not have a list of feeds Dim feeds As List(Of RSSFeed) = New List(Of RSSFeed) ? ? – Vector Jan 10 '22 at 22:36
  • I've updated the post with regards to IIS. Were you able to create the project as `ASP.NET Web Application (.NET Framework)`? I don't understand your last comment. – Tu deschizi eu inchid Jan 11 '22 at 01:25
  • @user9938I have applied the IIS setting as of this morning will give it a go As for my comment The code talks about a List(Of RSSFeed) I am guessing that as the code is now I can only view one website? Need DB with multiple sites to populate a DataGridView but that is beyond the scope of the issues NOW Added screen shot of Error and no idea how to fix it but will work on it. Why would all the IIS settings be OFF? – Vector Jan 11 '22 at 15:44
  • If one is using a laptop/desktop computer for developing, a version of IIS may be available, but the features aren't installed by default because IIS consumes resources. If it's not used, why enable it. If one is using a web server, obviously this won't apply. – Tu deschizi eu inchid Jan 11 '22 at 16:19
  • It is making my Dell Precision SING so when I am done with this application can I un-check all the settings ? – Vector Jan 11 '22 at 16:26
  • In Solution Explorer, right-click `default.aspx`. Then select `View Code Gen File`. You should see `Partial Public Class _default...` – Tu deschizi eu inchid Jan 11 '22 at 16:26
  • Once you no longer need IIS features, you can turn them off. – Tu deschizi eu inchid Jan 11 '22 at 16:27
  • 1
    I've updated the code to work with multiple URLs. – Tu deschizi eu inchid Jan 11 '22 at 16:41
  • Thanks for multiple site code Still have the same Error and I had to add these lines Debug.WriteLine(errMsg) commented out and Private gvRss As Object I understand both of these RSSFeed Class is added to App_Code I am sure that is OK ? YES created but same ERROR Message – Vector Jan 11 '22 at 16:58
  • Were you able to create the project as `ASP.NET Web Application (.NET Framework)`? – Tu deschizi eu inchid Jan 11 '22 at 17:01
  • Here is a link https://stackoverflow.com/questions/49868708/fix-for-system-web-httpexception-the-file-has-not-been-pre-compiled-and-cann – Vector Jan 11 '22 at 17:06
  • I did View Component Designer and View Design it runs the page and gives me a page with Downloads and Read Me AND I can not open anything that looks like your Update Post Hang on I am using the wrong file It needs to be Default.aspx.vb cant find this default.aspx.designer.vb – Vector Jan 11 '22 at 18:03
  • I tried adding just the three lines of code Protected WithEvents to Default.aspx.vb I have Options ON in VS but added that as well commented out all other code and ran THEN un commented all other code and ran STILL same ERROR Option Strict ON disalows Late Binding ? – Vector Jan 11 '22 at 18:37
  • It looks like for "Create a new ASP.NET Web Application", you chose `Web Forms` instead of `Empty`. Therefore, you'll have to modify some things. I suggest you first create the project as per my post to ensure you can get it to work before trying to make modifications. Also before you start, ensure that you have `Option Strict` turned on (Project => RSSFeedReader Properties => Compile => Option Strict: On) – Tu deschizi eu inchid Jan 11 '22 at 20:00
  • I Do Not see Compile when I Click Project on the top Menu Tried Right Click the RSSFeedReader in the Solutions View Also I was sure I selected Empty but that will be proven when I start over BUT lets clear up Option Strict.ON first VB defaults both are ON in Visual Studio – Vector Jan 11 '22 at 22:05
  • OK It runs will NO Error but the only thing it does is display this line of code

    Read RSS Feeds

    I know one of my mistakes I did not un check Configure for HTTPS Will post a NEW VIEW of Solution Explorer
    – Vector Jan 11 '22 at 23:01
  • 1
    Run the program in the debugger in VS (Debug => Start Debugging). – Tu deschizi eu inchid Jan 11 '22 at 23:18
  • 1
    For now, use `Debug`, and uncomment `Throw ex`, so that if any errors occur it will show you what the error is. When you use it normally, you'll most likely want to comment out `Throw ex` and instead log any errors. – Tu deschizi eu inchid Jan 11 '22 at 23:31
  • here is the ERROR msg - $exception {"The request was aborted: Could not create SSL/TLS secure channel."} System.Net.WebException – Vector Jan 11 '22 at 23:35
  • 1
    That's great news. The error doesn't occur on Win 10, but I also encountered it when running it on Win 7. It has to do with TLS. I found a solution though. Create a new post for this issue. – Tu deschizi eu inchid Jan 11 '22 at 23:40
  • Same message and NOW it is protesting Throw ex I did the FIX Shut down and restarted the computer ? – Vector Jan 12 '22 at 00:29
  • Did you also add the registry entries that were added to the post? – Tu deschizi eu inchid Jan 12 '22 at 00:37
  • See my post on other question NO I did not add them NOR I am not sure how to add I can do edit – Vector Jan 12 '22 at 00:42
  • @user998 It is NOT BAD News but if the YouTube site does not have the little RSS Feed Sticker Our RSSFeedReader will not work I tried this link below and Throw(ex) still not happy https://www.youtube.com/channel/UCBB7sYb14uBtk8UqSQYc9-w Don't Know if that will solve my NO RSS Feed for a YouTube May just write a App that has links in the DB and click on Button in DataGridView to open link None the less I learned a lot on this Project Mostly how to read ha ha – Vector Jan 12 '22 at 01:53
  • Now that you have it working. I've added "Update 2" which shows the changes necessary to make it work if you select "Web Forms" for "Create a new ASP.NET Web Application" instead of "Empty" – Tu deschizi eu inchid Jan 12 '22 at 01:53
  • According to [this video](https://www.youtube.com/watch?v=WmbPhkW8PHQ) the RSS feed would be https://www.youtube.com/feeds/videos.xml?channel_id=UCBB7sYb14uBtk8UqSQYc9-w which you can open in a browser. It appears that some of the XML elements have different names, so the code will have to be modified to read the desired elements. – Tu deschizi eu inchid Jan 12 '22 at 02:29
  • Added code to retrieve the RSS feed for the specified URL. – Tu deschizi eu inchid Jan 12 '22 at 04:10