问题
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