►问题:任何人都可以访问网页,但我只希望登录用户有权访问它。
背景:
示例网址:
A. "www.webpage.com/logon.aspx"
B. "www.webpage.com/inside.html"
期望的结果:
每个人都可以访问“logon.aspx”页面
只有登录用户才能访问“inside.html”页面
任何直接尝试访问“B”都会触发重定向到“A”
无需额外使用程序代码
之前的尝试: 我一直在摆弄web.config文件(身份验证和授权),但无济于事(501 Server Error,401 Authorization Error,Runtime Application Error)。
Web.Config文件:
<system.web>
<authentication>
<forms name=".ASPXFORMSAUTH" loginUrl="logon.aspx" protection="All" timeout="1" path="/" slidingExpiration="true" requireSSL="false" />
</authentication>
<authorization></authorization>
</system.web>
结论:我确信这是一个非常基本/简单的配置,只是到目前为止我还没能做到。另外,我不想编写任何额外的代码来完成看似基本的任务。
提前致谢!
答案 0 :(得分:0)
好的,我想通了(7小时后)。它需要四件事(基于示例文件结构):
<小时/>
FormsAuthentication
模块 VS2012→项目→您的凭据/身份验证码→使用FormsAuthentication.RedirectFromLogin(_var1_, _var2_)
代替Response.Redirect(inside.html)
<小时/>
web.config
文件<system.webServer><handlers><add name="HTMLHandler" type="System.Web.StaticFileHandler" path="*.html" verb="GET" /></handlers>
<小时/>
Forms
标记<forms name=".ASPXFORMSAUTH" loginUrl="logon.aspx" defaultUrl="inside.html" protection="All" timeout="1" path="/" slidingExpiration="false" requireSSL="false" />
<小时/>
<location path="inside.html"><system.web><authorization><deny users="?" /></authorization></system.web></location>
请参阅我的评论(下文),了解这四个部分中的每一部分。