Publish a CSS file in IIS

I am new to using IIS. I published an ASP.NET application on an IIS server, the application uses a third-party HTML loader that loads HTML but does not apply the effects from the .css file when I published. I add the following in the main HTML tag

<link href="~/input/docgenix.css" rel="stylesheet" type="text/css" /> 

I saved the CSS file in the input folder of the published application.

On the other hand, if you add HTML from the source of an existing page from the Internet along with a link to your CSS file, you can see the effects of the CSS file in action. For instance:

 <link rel="stylesheet" type="text/css" href="http://cdn.sstatic.net/stackoverflow/all.css"> 

I assume that my CSS is not published with my application. Please help me. How can I publish this CSS file correctly?

+4
source share
2 answers

Part ~ the file path (which means "application root") is not recognized on the client side.

You have two options: generate the server side <link> on the server side ( runat="server" ) and fill in the href attribute here (where ~ recognized using Page.ResolveUrl() )) or, alternatively, build the corresponding relative path, which does not include tilde (which is probably more efficient).

Relative path

Perhaps you just need to lose the tilde ( ~ ) if the application is hosted at the root level of the domain:

 <link href="/input/docgenix.css" rel="stylesheet" type="text/css" /> 

Server side solution:

This will work regardless of whether the web application is hosted at the root domain level or inside the folder ( mysite.com/myapp vs mysite.com ), but probably a little less efficient.

In the markup:

 <link id="lnk" runat="server" rel="stylesheet" type="text/css" /> 

and in code:

 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { lnk.Attributes["href"] = Page.ResolveUrl("~/input/docgenix.css"); } } 

(Note: this is not verified)

+2
source

Have you tried this ?:

 <link href="<%= Page.ResolveUrl("~/input/docgenix.css") %>" rel="stylesheet" type="text/css" /> 
+1
source

Source: https://habr.com/ru/post/1447903/


All Articles