在 Visual Studio 开发 Web 服务器上的 Azure Web 角色中访问 MVC 3 中的静态文件
在开发 Web 服务器中运行时,我在从 Azure + MVC 3 项目提供静态(图像)文件时遇到问题。我在网站上运行表单身份验证,并且任何图像请求都会通过登录重定向来满足。
我已经能够通过将我的图像文件夹设置为应用程序(通过 iis)并显式设置我的 Windows 用户来访问图像文件夹,尽管这仅适用于调试会话,并且显然不是真正的解决方案。
有几个问题不是:
- 映射路由拾取静态文件请求
- 文件夹权限不允许访问 NETWORK SERVICE 帐户
- web.config 中的规则需要对文件夹进行授权
当前图像驻留在 ~/Images/... 中,尽管我也将它们放在 ~/Content/... 中,这是主 css 所在的位置。说CSS总是服务没有任何问题。
值得注意的是,即使您登录,也不会提供图像。
我意识到,将这些图像存储在 blob 中可能会更好,尤其是在开发阶段,并且对于源代码控制,将这几个静态资源存储在一个 blob 中似乎更容易。项目文件夹。
编辑 - 问题不正确。实际上只是一个问题,一些文件在我的硬盘上被加密,而另一些则没有,导致奇怪的结果。
I'm having issues serving out static (image) files from an Azure + MVC 3 project when running in the dev web server. I have forms authentication running on the site, and any requests for images are met with a login redirect.
I have been able to make access possible by making my images folder an application (via iis) and explicitly setting my windows user to have access to the images folder, though this only works for a debugging session, and clearly isn't a real solution.
There are a couple of problems it isn't:
- Static file requests being picked up by mapped routes
- Folder permissions not allowing access to the NETWORK SERVICE account
- Rules in web.config requiring authorization for the folder
Currently the images reside in ~/Images/... though I have also had them in ~/Content/... which is where the main css resides. Said css always serves out without any issues.
Notably the images are not served even if you do log in.
I realise that it may be better to store these images in a blob, particularly in the development phase, and for source control, it seems easier to carry these few static resources in a project folder.
EDIT - Question was incorrect. Actually just an issue with some files being encrypted on my hd and others not, causing odd results.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,Windows 正在加密这些目录中的所有文件(这不是我的配置的标准行为,但由于某种原因发生在这里)。我有一些未加密的图像(包括 styles.css),但大多数图像都是加密的。这意味着如果没有我的凭据,图像将无法提供服务...
所以与 mvc / azure / cassini 无关!
It turns out windows was encrypting all of the files in these directories (not standard behaviour for my configuration, but was happening here for one reason or another). I had a couple of images that weren't encrypted (including the styles.css) but most of the images were. That meant that images wouldn't serve without my credentials against them...
So nothing to do with mvc / azure / cassini!
我的猜测是这是一些配置问题,与 Azure 本身无关。
可能值得尝试类似的问题/答案,例如:
我的 ASP.NET MVC2 应用程序使用表单身份验证甚至会阻止对图像、样式和脚本的访问
另外,如果您创建一个新项目,那么您是否会看到相同的效果?
My guess is that this is some config issue and is not related to Azure itself.
It is probably worth trying similar questions/answers like:
My ASP.NET MVC2 application with Forms Authentication is blocking access even to Images, Styles and Scripts
Also, if you create a new project then do you see the same effect?