【问题标题】:web site is redircting to wrong url hosted in locally网站正在重定向到本地托管的错误 url
【发布时间】:2013-12-23 08:42:56
【问题描述】:

我在 http://localhost/ 上托管的网站遇到了以下问题,该网站以前托管在 Visual Studio 上。我在 rool 文件夹中创建了文件夹名称 website4 并移动了网站。

然后我得到以下错误。

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: The virtual path '/assets/masters/homepage.master' maps to another application, which is not allowed.

Source Error: 


Line 1:  <%@ Page Language="C#" MasterPageFile="/assets/masters/homepage.master" Title="Content Page 1" %>
Line 2:  
Line 3:  <asp:Content ContentPlaceHolderID="Extra_dNet_Code" Runat="Server">

Source File: /WebSite4/default.aspx    Line: 1 

然后我将上面的网址('/assets/masters/homepage.master')更改为以下网址('~/assets/masters/homepage.master')。 之后我收到以下错误

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: The virtual path '/assets/stylesheets/css.ascx' maps to another application, which is not allowed.

Source Error: 


Line 1:  <%@ Master Language="C#" %>
Line 2:  <%@ Register Src="/assets/stylesheets/css.ascx" TagName="css" TagPrefix="include" %>
Line 3:  <%@ Register Src="/assets/javascripts/scripts.ascx" TagName="scripts" TagPrefix="include" %>
Line 4:  <%@ Register Src="/assets/header/header.ascx" TagName="header" TagPrefix="include" %>

Source File: /WebSite4/assets/masters/homepage.master    Line: 2

然后我把上面的url改成following

<%@ Register Src="~/assets/stylesheets/css.ascx" TagName="css" TagPrefix="include" %>
<%@ Register Src="~/assets/javascripts/scripts.ascx" TagName="scripts" TagPrefix="include" %>
<%@ Register Src="~/assets/header/header.ascx" TagName="header" TagPrefix="include" %>

但是它开始在没有 javascript 和 css 的情况下运行该网站。 当我单击图像时,它总是将站点重定向到没有 website4 的 URL 之后。类似这个网址的东西

`http://localhost/assets/images/...`

上面的链接应该是

http://localhost/website4/assets/images/...

或者它只是重定向到http://localhost.

如何解决这个问题?

【问题讨论】:

    标签: asp.net localhost web-hosting


    【解决方案1】:

    尝试指定您的MasterPage 相对网址,如下所示:

    <%@ Page Language="C#" MasterPageFile="~/assets/masters/homepage.master"  .. %>
    <%@ MasterType VirtualPath="~/assets/masters/homepage.master" %>
    

    请注意,当您执行 ~/ 时,asp.net 将查找 root/assets/masters/homepage.master

    不要只使用正斜杠,使用 ~ 即~/

    【讨论】:

    • 我已经提到我试过了。是否有任何配置可以在 asp.net 中指定基本 url?
    • 不,那你的解决方案肯定有问题,可能是重名
    • 我是 asp.net 的新手,你能解释一下吗?如何解决这个问题?
    • 所以告诉我,当您通过 Visual Studio 启动项目时,您的项目正在运行吗?而不是在 IIS 中托管它时?
    • 所以,首先,确认您的 IIS 支持构建项目的 DOT.NET 版本,您应该更好地搜索如何在 IIS 中托管 ASP.NET 站点(其简单的顺便说一句),此外,请注意以您在 html 文件中的方式包含您的 css 和 js 文件,然后执行此操作,&lt;script src='&lt;% ResolveUrl("~/relative path to js file") %/&gt;' /&gt;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-26
    • 1970-01-01
    • 2016-09-19
    • 1970-01-01
    • 2012-11-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多