Do MembershipProviders in ASP.net MVC affect stylesheet links?

有些话、适合烂在心里 提交于 2020-01-03 06:03:21

问题


I changed the MembershipProvider in my ASP.net MVC website, and now the stylesheet for the login page isn't referenced correctly. Below is a copy of the forms tag in my web.config if that could be the reason. It looks identical though to the one generated by a new project with the exception of the name and timeout attribute.

<authentication mode="Forms">
      <forms loginUrl="~/Account/Login" name=".ADAuthCookie" timeout="10" />
</authentication>

When I visit the page now, the link tag for the CSS looks like this:

<link href="../Content/Site.css" rel="stylesheet" type="text/css" />

When it should look like this:

<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />

回答1:


I haven't used ASP.NET MVC yet myself, but you could try using ResolveClientUrl when writing out the href for your CSS:

<link href="<%= ResolveClientUrl("../../content/Site.css") %> rel="stylesheet" type="text/css" />



回答2:


Thanks Ian Oxley. The problem wasn't solved with the ResolveClientUrl though.

It had to deal with the web.config file. I had code that looked like this:

<authorization>
  <deny users="?" />
  <allow users="*" />
</authorization>

I added a location element below the main one and said that anybody could view that content, and it works now. It turns out that files like the CSS file were not viewable until authorized before. That is now fixed.

This is what I added:

<location path="Content">
   <system.web>
      <authorization>
         <allow users="*" />
      </authorization>
   </system.web>
</location>


来源:https://stackoverflow.com/questions/167074/do-membershipproviders-in-asp-net-mvc-affect-stylesheet-links

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!