asp.net - 如何让我的 asp.net MVC 应用程序识别实时服务器上的样式表?

标签 asp.net asp.net-mvc css

我一直在使用 VWD2008 和随附的开发虚拟服务器构建我的示例 asp.net 应用程序。我已经到了要确保应用程序在实时服务器上正常运行的地步,所以我继续发布了它。一切似乎都很好地接受了样式表。没有任何样式应用于页面。我仔细检查了样式表的链接,并仔细检查了服务器位置。一切似乎都很好,并且与我的虚拟服务器上的版本相同。

链接是:<link rel="Stylesheet" type="text/css" href="/Content/Site.css" />

当我尝试浏览到样式表 (http://mydomain.com/Content/Site.css) 时,出现此错误:

Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Content/Site.css

你们知道是什么原因造成的吗?


编辑

我继续创建一个 test.html 并将其放入实时服务器的根目录中。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>test</title>
        <link rel="Stylesheet" type="text/css" href="/Content/Site.css" />
    </head>
    <body>
        <h1>Hi</h1>
    </body>
</html>

当我浏览到这个位置 (mydomain.com/test.html) 时,我收到另一个 404 错误。具体来说,我查看了错误页面的来源,发现了这个:

[HttpException]: The controller for path '/test.html' was not found or does not implement IController. at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

当我请求一个常规的 html 或 css 文件时,asp.net 似乎仍在使用路由。有没有办法解决。我可以在配置或路由中更改服务器设置或其他内容吗?

最佳答案

始终在处理 url 时使用 html 助手:

<link rel="Stylesheet" 
      type="text/css" 
      href="<%= Url.Content("~/Content/Site.css") %>" />

even betterMVCContrib :

<%= Html.Stylesheet("~/Content/Site.css") %>

关于asp.net - 如何让我的 asp.net MVC 应用程序识别实时服务器上的样式表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2951124/

相关文章:

c# - onchange = "Form.submit() 仅适用于我的下拉菜单中的第一个子下拉菜单

css - 在 CSS3 上的 Firefox 和 Opera 中卡住

c# - ASP.NET C# 在登录时显示地址详细信息

asp.net - "Your login attempt was not successful. Please try again"在 asp.net 中,尽管密码已重置

c# - 添加 asp :textbox dynamically in ASP. NET

asp.net-mvc - 将对象列表绑定(bind)到表单

c# - 提交表单导致 URL 中出现未知代码

asp.net-mvc - 将 json 数组返回到 ASP.NET MVC 的更优雅的方式

c# - Server.MapPath 返回错误的路径

JavaScript:本地存储 "boolean"未打开第一个函数调用