简体   繁体   English

ASP.NET web.config配置

[英]ASP.NET web.config configuration

I need to know how to configure my asp.net web.config file so that is has connection string to my database. 我需要知道如何配置我的asp.net web.config文件,以便它具有到数据库的连接字符串。 Here is the code I have in the file at this time: 这是我目前文件中的代码:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <tracing>
            <traceFailedRequests>
                <add path="*.asp">
                    <traceAreas>
                        <add provider="ASP" verbosity="Verbose" />
                        <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
                        <add provider="ISAPI Extension" verbosity="Verbose" />
                        <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI" verbosity="Verbose" />
                    </traceAreas>
                    <failureDefinitions statusCodes="500" />
                 </add>
            </traceFailedRequests>
        </tracing>
        <handlers>
            <remove name="AboMapperCustom-66406" />
        </handlers>
        <httpErrors errorMode="DetailedLocalOnly">
            <remove statusCode="412" subStatusCode="-1" />
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" path="/handle404.asp" responseMode="ExecuteURL" />
        </httpErrors>
    </system.webServer>
</configuration>

The connection string I need to integrate is as follows: 我需要集成的连接字符串如下:

server=214187-1;database=storeboard;uid=stuser;pwd=MyPassword

The connection string is required for the following page: 以下页面需要连接字符串:

<%@ Page Language="VB" EnableSessionState="True" %>
<%@Import Namespace="System" %>
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.SqlClient" %>
<%@Import Namespace="System.Configuration" %>
<%@Import Namespace="System.web" %>
<%@Import Namespace="System.Net" %>
<%@Import Namespace="System.Net.Mail" %>
<%@Import Namespace="System.Security.Cryptography" %>
<%@Import Namespace="System.Text" %>

    <script language="vbscript" runat="server">
    Dim UserName As String
    Dim oConn As SqlConnection
    Dim oCmd1 As SqlCommand
    Dim oCmd2 As SqlCommand
    Dim oCmd3 As SqlCommand
    Dim aConfig As ConfigurationSettings
    Dim strConn As String
    Dim strSQL As String
    Dim LastActivity As string 
    Dim ToAddress As String
    Dim ToName As String
    Dim BatchMailID as Integer
    Dim SessionID As String
    Dim Subject As String
    Dim Inactive as Boolean
    Dim Message As String
    Dim StillActive As Boolean = False

    Dim G_COOKIEROOT AS String = "STOREBOARD"



    Private Sub Page_Load()
        Dim dr As SqlDataReader

        SessionID = Request.Cookies(G_COOKIEROOT)("SESSIONID")
        Session("SessionID") = SessionID
        Response.Cookies(G_COOKIEROOT)("SESSIONID") = SessionID

        strConn = ConfigurationManager.AppSettings("ConnectionString")
        oConn = New SqlConnection(strConn)


        oConn.Open()
        If Trim(SessionID & "") <> "" Then
            strSQL = "sp_SessionData @MODE='UPDATEACTIVITY',@SessionID='" & SessionID & "'"
            oCmd1 = New SqlCommand(strSQL, oConn)
            dr = oCmd1.ExecuteReader()
            While dr.Read()
                StillActive = dr("StillActive")
            End While
            dr.Close()

        End If


    End Sub





</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ASP.NET Status Checker</title>
<meta http-equiv="refresh" content="60" />
</head>
<body>
SessionID: <%=SessionID%><br/>
<%=Now()%>
</body>
</html>

Any help with this issue would be greatly appreciated... 任何有关此问题的帮助将不胜感激...

Best Regards, Paul 最好的问候,保罗

Absolutely everything you need is here but you basically add the following tags to the root of web.config: 绝对需要的一切都在这里,但是您基本上将以下标记添加 web.config 的根目录中:

<connectionStrings>
  <add 
    name="NorthwindConnectionString" 
    connectionString="server=214187-1;database=storeboard;uid=stuser;pwd=MyPassword"
    providerName="System.Data.SqlClient"
  />
</connectionStrings>

and read it via: 并通过以下方式阅读:

ConfigurationManager.ConnectionStrings.ConnectionStrings["NorthwindConnectionString"];

You could've solved this with google. 你可以用谷歌解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM