我在加载时出现问题样式表 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