.net 4.8、VS 2019、VB.NET、IIS 10 在 Azure 中的 Windows 2016 VM 上運行。
我最近重新設計了我的網站。我有很多域名,無法解決這個問題。
我在 SQL Server 中設定了一個表。示例資料:
| 站點重定向器 ID | 服務器名稱 | UrlForNoStem | UrlForPreservedStem |
|---|---|---|---|
| 1 | 阿爾夫網 | [https://(例如.com)/arf.html] | [https : //(例如.com)/] |
| 2 | ribbit.com | [https://(例如.com)/frognoise.html] | [https : //(例如.com)/] |
| 3 | 喵喵網 | [https://(例如.com)/meow.html] | [https : //(例如.com)/] |
| 4 | 小號網 | [https://(例如.com)/elephants] | [https : //(例如.com)/] |
| 5 | www.bowwow.com | [https : //(例如.com)/] | [https : //(例如.com)/] |
所有服務器名稱都系結到此處的應用程式,但Url命名列中的服務器位于不同的應用程式上,也許是不同的機器上。
除了 global.asax 之外,重定向器應用程式沒有任何代碼,這里是所有代碼。Default.aspx 存在但為空白且沒有代碼隱藏。
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
Dim uCurrent As Uri = HttpContext.Current.Request.Url
Dim sReqHost As String = uCurrent.Host
Dim sReqUrl As String = uCurrent.AbsolutePath.Trim()
Dim sFullTail As String = uCurrent.PathAndQuery.Trim()
Dim sSearchHost As String = sReqHost.ToLower()
If sSearchHost.StartsWith("www.") Then
sSearchHost = sSearchHost.Replace("www.", "")
End If
If sSearchHost.StartsWith("ww.") Then
sSearchHost = sSearchHost.Replace("ww.", "")
End If
If sSearchHost.StartsWith("w.") Then
sSearchHost = sSearchHost.Replace("w.", "")
End If
Dim sConn As String = ConfigurationManager.ConnectionStrings("WS").ToString
Using DS As New DataSet()
Using Conn As New SqlClient.SqlConnection(sConn)
Conn.Open()
Dim sSQL As String = "select * from [SiteRedirector] where [ServerName] = @ServerName; "
Using Cmd As New SqlClient.SqlCommand(sSQL, Conn)
Cmd.Parameters.Add("@ServerName", SqlDbType.VarChar).Value = sSearchHost
Using DA As New SqlClient.SqlDataAdapter(Cmd)
Dim iRet As Integer = DA.Fill(DS)
End Using
End Using
Conn.Close()
End Using
If DS.Tables.Count < 1 OrElse DS.Tables(0).Rows.Count < 1 Then ' dead link
Response.Redirect("https://example.com/404.aspx")
End If
Dim sTarget As String = ""
If sFullTail.Trim() = "/" OrElse sFullTail.Trim() = "" Then
sTarget = DS.Tables(0).Rows(0)("URLForNoStem").ToString.Trim()
Else
sTarget = DS.Tables(0).Rows(0)("URLForPreservedStem").ToString.Trim()
If sTarget.EndsWith("/") AndAlso sFullTail.StartsWith("/") Then
sTarget &= sFullTail.Trim().Substring(1, sFullTail.Length - 1)
Else
sTarget &= sFullTail.Trim()
End If
End If
Server.ClearError()
Response.Clear()
Response.Redirect(sTarget)
End Using
End Sub
在本地測驗并使用即時視窗將測驗 URL 注入uCurrent變數時,對于所有 URL 和詞干組合,一切都完美無缺。完全按照設計。
但是,當部署到 IIS 時,沒有主干 [http :// ribbit.com] 的 URL 可以作業但有主干的 URL: [http : / / meow.com/hiss-scratch.html] 或 [http : / / ribbit .com/backbeat.html?FBCLID=whatever] 失敗并顯示 404。301 重定向似乎在我的重定向器站點處理發布后被覆寫。
我錯過了什么?
uj5u.com熱心網友回復:
答案是基于這樣一個事實,即 .html 擴展名通常不會路由到 global.asax。我能夠使用舊的 Intellegencia URLRewriter 并讓程式攔截 404 并將其發送到Application_Error事件。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/395536.html
標籤:网站 网络 global-asax
上一篇:在FlowPanel內克隆面板
