样式表CSS未加载Context.RewritePath

时间:2013-03-25 05:25:32

标签: asp.net vb.net visual-studio-2010 global-asax

使用asp.net VB Context.RewritePath 加载样式表 CSS时出现问题。

我的项目正在开发飞子域系统。意味着当我们在 abcUser.mydomain.com 中输入此内容时,它将从 mydomain.com/users/abcUser/default.aspx 获取abcUser的默认页面,而不更改地址栏的地址。 记住没有任何物理子域存在

如果用户名为文件夹,则在我的项目中存在,然后从/ users /<加载默认页面abcUser> /default.aspx

现在如果在浏览器中输入直接路径

  

例如:www.mydomain.com/users/< abcUser&GT; /default.aspx

然后加载css样式表,但如果我输入这样的路径:

  

例如:abcUser.mydomain.com

然后加载我的default.aspx页面但不加载css文件

  • 这是Global.asax Application_BeginRequest代码:

If Directory.Exists(Server.MapPath("~/users/" & parameters(i))) Then
   Context.RewritePath("/users/" & parameters(i) & "/default.aspx", False)                    
    Return
Else
    Context.RewritePath("/error.aspx")
    Return
End If

参数(i)变量包含在浏览器中作为子域输入的值,例如:abcUser。

  • 这是我的文件夹结构:

enter image description here

  • 这是我的default.aspx页面代码:

    <link href="StyleSheet.css" rel="stylesheet" />
    

额外细节:我为microsoft.aspnet.friendly.urls LINK安装了新的ASP.NET和Web Tools 2012.2更新。它按照承诺工作,我所有的新旧网页现在都很友好。我的项目是asp.net 4 webform 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", "/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("/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

1 个答案:

答案 0 :(得分:1)

我最终使用Server.TransferRequest。使用此方法时,问题似乎并未表现出来。我不知道为什么......