简体   繁体   中英

When using iis express no css applied on a remote pc

I came up with a necessity to work with my asp.net mvc site from a remote pc while developing. So, I configured it to use IIS Express.

At first, a problem raised with windows authentication. My site is supposed to work in windows domain intranet, so I wanted to use integrated windows authentication. I managed to make it work on firefox with How To: Firefox and Integrated Windows Authentication from IIS Express Windows Authentication (answer by bees73). But IExplorer still asks to print login/password, even if I open it locally, specifying my ip instead of localhost.

The issue with IE is still not resolved, but let it be - if I print in my credentials, it does work locally.

My question is: when I open my site on a remote PC (both in firefox (no need to print login/password) and IE (I do have to print login'n'password)) my page is rendered without applying styling. It looks like no css is available. But I don't get any errors.

In the source code of the loaded page I do have line

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

but when I try to see the Site.css, it says, there was some internal server error.

I think I did not configure IIS Express properly and that's the problem. If it was OK, the integrated windows authentication had to work without asking login and password on IE at least I guess.

So, my config:

  1. The project itself - to IIS Express, windows authentication - on, anonymous - off.
  2. netsh http add urlacl url= http://myip:myport user=domainname\\mylogin
  3. netsh http add iplisten ipaddres=myip
  4. in applicationhost.config :

Bindings:

 <site name="MySite" id="2"> <application path="/" applicationPool="Clr4IntegratedAppPool"> <virtualDirectory path="/" physicalPath="D:\\..." /> </application> <bindings> <binding protocol="http" bindingInformation="*:myport:localhost" /> <binding protocol="http" bindingInformation="*:myport:myip" /> </bindings> </site> 

Authentication:

 <sectionGroup name="authentication"> <section name="anonymousAuthentication" overrideModeDefault="Deny" /> ... <section name="windowsAuthentication" overrideModeDefault="Allow" /> </sectionGroup> 

 <authentication> <anonymousAuthentication enabled="false" userName="" /> ... <windowsAuthentication enabled="true"> <providers> <add value="Negotiate" /> <add value="NTLM" /> </providers> </windowsAuthentication> </authentication> 

 <add name="AnonymousAuthenticationModule" lockItem="true" /> 

 <location path="MySite"> <system.webServer> <security> <authentication> <anonymousAuthentication enabled="false" /> <windowsAuthentication enabled="true" /> </authentication> </security> </system.webServer> </location> 

The problem was connected with netsh and binding configuration in ISS Express. At first I setup it through my ip, and it resulted in confusing errors.

While searching for anything in the web I ran across Setting up IIS Express . All the same there, but it's suggested using pc name in netsh and iis applicationhost.config .

So, I added

netsh http add urlacl url=http://MyPCName:MyPort/ user=everyone

and

<binding protocol="http" bindingInformation="*:MyPort:MyPCName" />

and a miracle!! It worked.

As for the IE, I had to turn off the "Use Windows authorization" flag to make it work. Many thanks to Internet Explorer - Enable Integrated Windows Authentication . But nevertheless IE still asks for login and password, if an ip is used in url. If pc name is used it works silently.

Firefox either asks for login and password (and works if one enters valid credentials) or you should apply How To: Firefox and Integrated Windows Authentication (mentioned in my question) and then it works silently both with ip and pc name.

Hope this helps someone else.

EDIT

One remark: I had to launch VS2010 with administrtor permissions. If not, I still get HTTP 500 error based on the bad impersonation error. So, it looks like IIS Express, launched by VS2010 without administrator permissions under Windows 7, won't be able to work correctly.

As far as I understood, the clue is to give the appropriate permissions to IIS_IUSRS. But until that it's easier to launch VS 2010 with administrator privilages.

It may be due to the error in resolving the root path where Css is located. You can try with Url helpers to resolve this issue.

<link rel="stylesheet" type="text/css" href="@Url.Content("~/Content/Site.css")"  media="screen" />

In Asp.net development server(In visual studio environments) <link href="/Content/Site.css" rel="stylesheet" type="text/css" /> will work fine.. but while hosting in IIS, root path cannot be resolved using a relative path. With the help of Url helpers we can resolve this issue. Using Firebug you can see the load error of resources if any.

Edit:

In the web.config under the <system.web> section modify as follows.

 <system.web>
  <identity impersonate="true" userName="ServerName\Administrator" password="password"/>
 </system.web>

Give the proper values for username and password. You can try giving folder permission to the IIS user groups( IUSR , IIS_IUSR ) to the folder where application is hosted.(Right click the hosted folder -> Properties under the Security tab, you can find the user groups and can give permissions)

try placing a web.config file in you Content folder. and put the following code in it.

<?xml version="1.0"?>

<configuration>
    <system.web>
        <authorization>
            <allow users="*" />
        </authorization>
    </system.web>
</configuration>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM