如何使用 ASP.NET 在纯 HTML 页面上进行表单身份验证?
我在 IIS7 中使用表单身份验证来对开发站点进行密码保护,但是当站点仅包含静态 HTML 文件 + login.aspx + web.config 时,身份验证似乎会被绕过。
当我将文件重命名为 .aspx 时,系统会提示我输入登录表单 我没有做任何花哨的事情。我有一个非常简单的登录脚本,之后它应该重定向到index.html。
有什么建议吗?总而言之,整个网站(目前)使用 HTML,并且需要密码保护。
<authentication mode="Forms">
<forms name="appNameAuth" path="/" loginUrl="~/login.aspx" defaultUrl="index.html" protection="All" timeout="525600">
<credentials passwordFormat="Clear">
<user name="[user]" password="[password]" />
</credentials>
</forms>
</authentication>
<authorization>
<deny users="?" />
</authorization>
I am using forms authentication in IIS7 to password-protect a dev site, but the authentication seems to get by-passed when the site contains only static HTML files + login.aspx + web.config.
When I renamed the files to .aspx, I am prompted with the login form
I am not doing anything fancy. I have a very simple login script and it should just redirect to index.html afterward.
Any suggestions? To summarize, the entire site is using HTML (for now) and needs to be password protected.
<authentication mode="Forms">
<forms name="appNameAuth" path="/" loginUrl="~/login.aspx" defaultUrl="index.html" protection="All" timeout="525600">
<credentials passwordFormat="Clear">
<user name="[user]" password="[password]" />
</credentials>
</forms>
</authentication>
<authorization>
<deny users="?" />
</authorization>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 IIS7 中,如果您想在表单身份验证下保护 *.html 或 *.htm 文件(或其他非 .net 扩展名),请将以下行添加到您的 web.config 中:
并且
In IIS7 if you want to protect *.html or *.htm files (or other non .net extensions) under forms authentication then add the following lines to your web.config:
AND
要通过表单身份验证锁定 HTML 文件,您需要让 ASP.NET 为它们提供服务。您可以在 IIS 中通过将所需的扩展名(例如 .html、.htm 等)与 aspnet_isapi.dll 相关联来执行此操作。
一旦 ASP.NET 为这些文件提供服务,您就可以像任何 aspx 页面一样指定它们的权限。
有关详细信息,请参阅 MSDN:
To make the HTML files locked down by your forms authetication, you need have them served by ASP.NET. You can do this in IIS by associating the extension(s) you need (eg. .html, .htm, etc) with the aspnet_isapi.dll.
Onces ASP.NET is servicing those files you can specify the permissions for them just like any aspx page.
For more information refer to MSDN:
虽然这是一个老问题,但我发现 pomarc 的答案中的链接非常有用。以下是适用于 IIS7 的摘要。
在
web.config
中,添加或修改
下的
:替换
verb
符合您所需的价值;scriptProcessor
值与您的环境的正确路径。然后,添加或修改
下的
和
:替换
verb 值与您需要的值。
您还可以包含更多用逗号“,”分隔的扩展名
Although this is an old question, I find the link in pomarc's answer really useful. Below is the summary which is suit for IIS7.
In your
web.config
, add or modify<handlers>
under<system.webServer>
:Replace
verb
value with your required one;scriptProcessor
value with correct path of your environment.Then, add or modify
<compilation>
and<httpHandlers>
under<system.web>
:Replace
verb
value with your required one.You may also include more extension separated by comma ','
几天前,我通过关注 fr33m3 @ 11-21-2007, 3:19 PM 在这个线程上的帖子解决了同样的问题:
http://forums.asp.net/t/1184547.aspx
遵循 2. 至 5. 的所有步骤即可完成!
希望这可以帮助你,就像它帮助我一样。
I've solved the same problem a few days ago, by following the post by fr33m3 @ 11-21-2007, 3:19 PM on this thread:
http://forums.asp.net/t/1184547.aspx
follow all the steps from 2. to 5. and you're done!
hope this can help you like it helped me.