我在加載時出現問題樣式表 CSS with asp.net VB Context.RewritePath。樣式表CSS沒有用Context.RewritePath加載
我的項目正在研究飛子站系統。意思是當我們輸入abcUser.mydomain.com時,它會從mydomain.com/users/abcUser/default.aspx得到abcUser的默認頁面,而不改變地址欄的地址。 記得沒有任何物理子域存在。
在我的項目中,如果存在用戶命名的文件夾,那麼它會從/ users/< abcUser> /default.aspx加載默認頁面。
現在如果在瀏覽器中輸入我的直接路徑
如:www.mydomain.com/users/ < abcUser> /default.aspx
然後將其加載CSS樣式表,但如果我進入路徑是這樣的:
如:abcUser.mydomain.com
然後將其加載我的Default.aspx頁面,但不能加載CSS文件
- 這是Global.asax中的Application_BeginRequest代碼:
。
If Directory.Exists(Server.MapPath("~/users/" & parameters(i))) Then
Context.RewritePath("https://stackoverflow.com/users/" & parameters(i) & "/default.aspx", False)
Return
Else
Context.RewritePath("/error.aspx")
Return
End If
參數(i)變量包含在子瀏覽器中輸入的值,例如:abcUser。
- 這是我的文件夾結構:
這是我的Default.aspx頁面代碼:
<link href="StyleSheet.css" rel="stylesheet" />
額外的細節:我安裝ñ ew ASP.NET和Web Tools 2012.2 Update for microsoft.aspnet.friendly.urls LINK。並且它按照承諾進行工作,我的所有新老網頁現在都很友好。我的項目是asp.net Web窗體4 IIS7
的Global.asax代碼:
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
Dim fullHostPath As String = Request.Url.ToString()
Dim url As New System.Uri(fullHostPath)
Dim fullDomain As String = url.Host
Dim parameters() As String = fullDomain.Split(".")
Dim originalPath As String = HttpContext.Current.Request.Path.ToLower()
'
For i As Integer = 0 To parameters.Length - 1
If parameters(i) = "localhost" Or parameters(i) = "abc" Then
'if User enter www.abc.com
parameters(i) = 0
Return
End If
If parameters(i) = "www" Then
'if User enter WebName with "www" eg: www.jasbir.abc.com
'i+=1 gives the next array value, next array is the user name in "fulldomain" variable
i += 1
GlobalUserNameVar = parameters(i) ' get current subdomain name and store for CSS
If parameters(i) <> "abc" Then
If originalPath.Contains("/dashboard") And Directory.Exists(Server.MapPath("~/users/" & parameters(i))) Then
'check is full path contains "/dashboard" keyword if yes then move to this:-
Context.RewritePath(originalPath.Replace("/dashboard", "~/dashboard"), False)
Return
ElseIf originalPath.Contains("/profile") And Directory.Exists(Server.MapPath("~/users/" & parameters(i))) Then
'check is full path contains "/profile" keyword if yes then move to this:-
Context.RewritePath(originalPath.Replace("/profile", "https://stackoverflow.com/users/" & parameters(i) & "/profile"), False)
Return
ElseIf Directory.Exists(Server.MapPath("~/users/" & parameters(i))) Then
'check user named directory exists or not if yes then do this:-
HttpContext.Current.Server.TransferRequest("https://stackoverflow.com/users/" & parameters(i) & "/default.aspx", False)
Return
Else
Context.RewritePath("/error.aspx")
Return
End If
Else
Return
End If
End If
Next
這是Default.aspx頁面代碼
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
function oGod(textboxID, NewValue, textboxUserName) {
var resultData;
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "default.aspx/HelloWorld",
data: '{ "varTextBoxID" : "' + textboxID + '", "varNewData" : "' + NewValue + '", "varUserName": "' + textboxUserName + '"}',
dataType: "json",
async: false,
success: function (msj) {
resultData = msj.d;
return resultData;
},
error: function (e) {
resultData = "error";
return resultData;
}
});
return resultData;
}
Default.aspx的。vb代碼
<WebMethod()> _
Public Shared Function HelloWorld(varTextBoxID As String, varNewData As String, varUserName As String)
Dim tempData As String = Nothing
If varTextBoxID = "edit_main_contents" Then
tempData = UpdateHouseDatabase(varTextBoxID, varNewData, varUserName)
End If
If varTextBoxID = "edit_second_contents" Then
tempData = UpdateHouseDatabase(varTextBoxID, varNewData, varUserName)
End If
If varTextBoxID = "user_ID" Then
tempData = varNewData
End If
Return tempData
End Function
您是否找到了解決該問題的方法? – 2013-11-07 12:24:01
不,我盡我所能,但不幸的是我無法找到解決方案。我的項目工作因爲這個問題而停止。如果你會找到解決方案,那麼請與我分享。我會欣賞 – 2013-11-10 11:50:14
我已經使用'Server.TransferRequest'來解決問題,但我不知道爲什麼。 – 2013-11-10 17:13:30