【发布时间】:2018-01-31 17:20:23
【问题描述】:
我在 IIS 8 中有一个 ASP .NET MVC 站点,该站点使用表单身份验证进行保护。在此站点中,我有子站点(这是通过 IIS 8 中的“添加应用程序”选项创建的应用程序)。该子站点由静态 html 页面组成。所以例如我的主站点 URL 是 www.site.com。子站点网址是 www.site.com/mysite。
我需要配置 mysite,这样如果用户登录到 www.site.com,则只能访问 mysite。尝试直接访问 mysite 应该重定向到 www.site.com 登录页面。
我在这方面搜索了很多,并在 SO 中找到了一些文章。
尝试 1: How do I protect static files with ASP.NET form authentication on IIS 7.5?
基于这个 SO question,我尝试更改父站点的 web.config。我在这里提一下
<system.webServer>
<modules>
<add name="FormsAuthenticationModule" type="System.Web.Security.FormsAuthenticationModule" />
<remove name="UrlAuthorization" />
<add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" />
<remove name="DefaultAuthentication" />
<add name="DefaultAuthentication" type="System.Web.Security.DefaultAuthenticationModule" />
</modules>
</system.webServer>
<system.web>
<authorization>
<deny users="?" />
</authorization>
<authentication mode="Forms">
<forms defaultUrl="/Home/Index" loginUrl="/" protection="All" timeout="90">
</forms>
</authentication>
</system.web>
但是,通过这些设置,当我尝试打开 www.site.com/mysite 时,它会将我重定向到带有 www.site.com?returnUrl=mysite 的登录页面。但是登录后它再次将我重定向到登录页面
尝试 2: How to do Forms Authentication on purely HTML pages using ASP.NET?
根据这个 SO question,我尝试通过在子站点 (mysite) 的 web.config 中添加以下内容,使子站点 www.site.com/mysite 由 ASP .NET 处理。然而没有快乐
<compilation>
<buildProviders>
<add extension=".html" type="System.Web.Compilation.PageBuildProvider" />
<add extension=".htm" type="System.Web.Compilation.PageBuildProvider" />
</buildProviders>
</compilation>
尝试 3:
我尝试直接在子站点 (www.site.com/mysite) 的 web.config 文件中添加表单身份验证和授权设置
<system.web>
<authorization>
<deny users="?" />
</authorization>
<authentication mode="Forms">
<forms defaultUrl="/Home/Index" loginUrl="/" protection="All" timeout="90" domain="site.com">
</forms>
</authentication>
</system.web>
这里要注意的重要一点是
域名
属性添加到表单标签。还是不开心!
现在我想知道我正在尝试的东西是否可能?或者有没有我可能不知道的替代解决方案?
【问题讨论】:
标签: asp.net asp.net-mvc authentication authorization iis-8