Authorization Issue - anonymous users can't access .jpeg or .css

别说谁变了你拦得住时间么 提交于 2019-12-21 04:28:43

问题


I have this on my web.config file:

<authentication mode="Forms">
      <forms loginUrl="login.aspx" defaultUrl="Venues.aspx" />
    </authentication>
    <authorization>
      <deny users="?" />
      <allow users="*" />
</authorization>

I only want to allow authenticated users to my pages. The problem is, the first time that I go to the login page, I don't have any images or styles on my page. I think this is because I denied access to the .jpeg and .css files. I think I can solve this issue in IIS, but I'm just in Dev. I only have VS 2008 and no IIS.

Is it possible for me to allow access to the imgs dir for the anonymous user in the web.config?


回答1:


You could allow certain directories (directly under <configuration>):

<location path="images">
    <system.web>
        <authorization>
            <allow users="?"/>
        </authorization>
    </system.web>
</location>

Also you would probably need to include WebResource.axd

<location path="WebResource.axd">
    <system.web>
        <authorization>
            <allow users="?"/>
        </authorization>
    </system.web>
</location>



回答2:


I think this is a known bug in Visual Studio - when you're not using IIS, visual studio mistakenly blocks the CSS file on the login page.

See here:
blog post from tomtech999

It should be OK when you run in IIS.




回答3:


Similarly, if you want Microsoft's ReportViewer control to work on your web page, you need to add this:

<location path="Reserved.ReportViewerWebControl.axd">
  <system.web>
    <authorization>
      <allow users="*"/>
    </authorization>
  </system.web>
</location>

This was a problem for me while attempting to get the 2010 version of report viewer to work. (Fortunately, it only took 7 billion years to uncover the source of the problem.)



来源:https://stackoverflow.com/questions/811396/authorization-issue-anonymous-users-cant-access-jpeg-or-css

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