.NET ASP VB点击计数器

 收藏

我正在尝试打一个柜台。我可以使用它,但是当我将其添加到我的网站时,会得到一个Web配置。错误...

<%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="false"
    CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Import Namespace="System.IO" %>

    <script language="VB" runat="server">

        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            If Not Page.IsPostBack Then
                Dim nCount As Int32 = 0
                nCount = GetCounterValue()
                lblHitCount.Text = nCount.ToString()
            End If

        End Sub

        Private Function GetCounterValue() As Int32

            Dim ctrFile As StreamReader
            Dim ctrFileW As FileStream
            Dim sw As StreamWriter
            Dim strPath As String = Server.MapPath("indexcount.txt")
            Dim strCounterContents As String
            Dim nCounter As Int32

            If (File.Exists(strPath)) Then
                ctrFile = File.OpenText(strPath)
                strCounterContents = ctrFile.ReadLine().ToString()
                ctrFile.Close()
                nCounter = Convert.ToInt32(strCounterContents)

            Else
                nCounter = 0

            End If

            nCounter += 1
            ctrFileW = New FileStream(strPath, FileMode.OpenOrCreate, FileAccess.Write)
            sw = New StreamWriter(ctrFileW)
            sw.WriteLine(Convert.ToString(nCounter))
            sw.Close()
            ctrFileW.Close()

            Return nCounter

        End Function

    </script>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">

    <style type="text/css">

        .style2 {
            color: #000066;
        }
        .style3 {
            text-decoration: underline;
        }
        .style5 {
            color: #000066;
            font-weight: bold;
        }

    </style>

</asp:Content>

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

    <h2>
        <span class="style5"><strong>Welcome to Beebe Automotive Service!</strong></span>
    </h2>

    <p>
        <span class="style2"><span class="style3">Location:</span> One mile North of Rock Falls 
        on Highway 85</span>
    </p>

    <p>
        <marquee class="style2"">We Are <span class="style3">Now Accepting Appointments</span>!!!</marquee>
    </p>

    <p class="style2">
        <span class="style3">Call:</span> (715)672-3261
    </p>

    <p>
        <span class="style2">Or <span class="style3">Contact:</span> 
        <a href="mailto:customerservices@beebeauto.com" style="color: #3333FF">customerservices@beebeauto.com</a></span>
    </p>

    <p class="style2">
        Like us on Facebook:  
        <a href="https://www.facebook.com/beebeauto" 
            style="color: #3333FF">Beebe Automotive Service
        </a>
    </p>

    <p class="style2">
        Thank you for visiting. You are visitor number: 
    </p>

    <p class="style2">
        <asp:label ID="lblHitCount" runat="server" Height="38px" Width="200px" 
            Font-Bold="True" Font-Size="X-Large" ForeColor="#000066">
        </asp:label>
    </p>

</asp:Content>

我收到此错误:

Server Error in '/' Application.

Runtime Error

Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine. 

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".


<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>

Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.


<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
    </system.web>
</configuration>
回复
  • 妮听咱话 回复

    您上传了indexcount.txt吗?

    编辑:嗯,你做了检查... 您可能需要打开调试一分钟。这是一个选择吗?

    编辑2:我没有大量的IO经验,但是读取空文件会得到什么?您是否上传了“新鲜”的空文本文件?也许您正在尝试将空字符串转换为int32?

  • Wooll 回复

    该错误告诉您,如果要查看实际错误,请将自定义错误设置为OFF或仅将其设置为远程,但仅使用远程,则只会看到该错误是从Web服务器本身浏览。

    只需暂时将其设置为关闭,即可获取详细信息。

  • bipsam 回复

    我上传了indexcount ...

    编辑2:我认为情况并非如此...

  • 第五以南 回复

    我意识到了,但是为什么不运行呢?当我从VS运行它时,它可以工作...