CSS样式表不Context.RewritePath加载 [英] Stylesheet CSS not loading with Context.RewritePath

查看:370
本文介绍了CSS样式表不Context.RewritePath加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在加载的样式越来越问题 CSS用asp.net VB Context.RewritePath

我的项目正在飞子系统。意味着当我们在 abcUser.mydomain.com ,然后它会得到abcUser的默认页从 mydomain.com/users/abcUser/default.aspx 后,在不改变地址栏的输入该地址。的记住没有任何物理子存在的。

在我的项目,如果用户命名的文件夹存在,那么它从/用户/&LT加载默认的页面; abcUser> /default.aspx。

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


  

例如:www.mydomain.com/users/< abcUser> /default.aspx


然后将其加载CSS样式表,但如果我输入的路径是这样的:


  

例如:abcUser.mydomain.com


然后,它加载我Default.aspx页,但不加载CSS文件


  • 这是Global.asax中的Application_BeginRequest code:

 如果Directory.Exists(使用Server.Mappath(〜/用户/&放大器;参数(I)))然后
   Context.RewritePath(/用户/&放大器;参数(我)及/default.aspx,假)
    返回
其他
    Context.RewritePath(/ error.aspx)
    返回
万一

参数(我)变量包含在浏览器中输入作为子如值:abcUser


  • 这是我的文件夹结构:


  • 这是我的Default.aspx页面code:

     &LT;链接HREF =stylesheet.css中的rel =stylesheet属性/&GT;


额外的细节:我安装了新的ASP.NET和Web工具2012.2更新microsoft.aspnet.friendly.urls <一个href=\"http://weblogs.asp.net/scottgu/archive/2013/02/18/announcing-release-of-asp-net-and-web-tools-2012-2-update.aspx\"相对=nofollow>链接。并且它正在如许,我所​​有的新新老网页现在是友好的。我的项目是asp.net 4表单IIS7

的Global.asax code:

 子的Application_BeginRequest(BYVAL发件人为对象,BYVAL E上的EventArgs)
    昏暗fullHostPath作为字符串= Request.Url.ToString()
    昏暗的URL作为新的System.Uri(fullHostPath)
    昏暗fullDomain作为字符串= url.Host
    昏暗的参数()作为字符串= fullDomain.Split(。)
    昏暗originalPath作为字符串= HttpContext.Current.Request.Path.ToLower()
        对于我作为整数= 0〜parameters.Length - 1
        如果参数(I)=本地主机或参数(I)=ABC然后
            如果用户输入www.abc.com
            参数(ⅰ)= 0
            返回
        万一
        如果参数(I)=WWW然后
            如果用户以WWW,例如输入网站名称:www.jasbir.abc.com
            的i + = 1给出了下一个数组值,下一个阵列是用户名中的fulldomain可变
            I + = 1
            GlobalUserNameVar =参数(我)'获得当前的子域名和存储CSS
            如果参数(ⅰ)所述;&GT; ABC然后
                如果originalPath.Contains(/仪表板)和Directory.Exists(使用Server.Mappath(〜/用户/&放大器;参数(I)))然后
                    检查是完整路径包含/仪表板的关键字,如果是,则移动到这一点: -
                    Context.RewritePath(originalPath.Replace(/仪表板,〜/仪表板),FALSE)
                    返回
                elseif的originalPath.Contains(/配置文件)和Directory.Exists(使用Server.Mappath(〜/用户/&放大器;参数(I)))然后
                    检查是完整路径包含/ profile文件的关键字,如果是,则移动到这一点: -
                    Context.RewritePath(originalPath.Replace(/配置文件,/用户/&放大器;参数(我)及/配置文件),FALSE)
                    返回
                elseif的Directory.Exists(使用Server.Mappath(〜/用户/&放大器;参数(I)))然后
                    检查用户指定的目录存在与否如果是那么这样做: -
                    HttpContext.Current.Server.TransferRequest(/用户/&放大器;参数(我)及/default.aspx,假)
                    返回
                其他
                    Context.RewritePath(/ error.aspx)
                    返回
                万一
            其他
                返回
            万一
        万一
        下一个

这是Default.aspx页面code

 &LT;脚本类型=文/ JavaScript的字符集=utf-8&GT;
    $(文件)。就绪(函数(){
    功能oGod(textboxID,的NewValue,textboxUserName){
        VAR resultData;        $阿贾克斯({
            键入:POST,
            的contentType:应用/ JSON的;字符集= UTF-8,
            网址:的Default.aspx / HelloWorld的,
            数据:{varTextBoxID:+ textboxID +',varNewData:+的NewValue +',varUserName:+ textboxUserName +'},
            数据类型:JSON
            异步:假的,
            成功:函数(MSJ){
                resultData = msj.d;
                返回resultData;
            },
            错误:功能(E){
                resultData =错误;
                返回resultData;
            }        });        返回resultData;
    }

default.aspx.vb code

 &LT;的WebMethod()GT; _
公共共享功能的HelloWorld(varTextBoxID作为字符串,varNewData作为字符串,varUserName作为字符串)
    昏暗的TempData作为字符串=没有    如果varTextBoxID =edit_main_contents然后
        TempData的= UpdateHouseDatabase(varTextBoxID,varNewData,varUserName)
    万一
    如果varTextBoxID =edit_second_contents然后
        TempData的= UpdateHouseDatabase(varTextBoxID,varNewData,varUserName)
    万一
    如果varTextBoxID =USER_ID然后
        TempData的= varNewData
    万一    返回的TempData
结束功能


解决方案

我结束了使用 Server.TransferRequest 。似乎这个问题并不当使用这种方法来表现出来。我不知道为什么...

I am getting problem in loading stylesheet CSS with asp.net VB Context.RewritePath.

My project is working on fly subdomain system. Means when we enter this in abcUser.mydomain.com then it will get default page of abcUser from mydomain.com/users/abcUser/default.aspx, without changing address bar's address. remember there is no any physical subdomain exists.

in my project if user named folder exists then it load the default page from /users/< abcUser>/default.aspx.

now if in browser i enter direct path

eg: www.mydomain.com/users/< abcUser>/default.aspx

then it load css stylesheet, but if i enter path like this:

eg: abcUser.mydomain.com

Then it load my default.aspx page but not loading css file

  • This is Global.asax Application_BeginRequest code:

.

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

Parameters(i) variable contains the value entered in browser as subdomain eg: abcUser.

  • This is my folder structure:

  • This is my default.aspx page code:

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

Extra Detail: i installed new ASP.NET and Web Tools 2012.2 Update for microsoft.aspnet.friendly.urls LINK. and it is working as promised, my all new new and old web pages are now friendly. my project is asp.net 4 webform iis7

Global.asax code:

  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

This is default.aspx page code

<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 code

<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

解决方案

I ended up using a Server.TransferRequest. The problem doesn't seem to manifest itself when this method is used. I don't know why...

这篇关于CSS样式表不Context.RewritePath加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆