2017-02-16 25 views
0

我有一个关于Azure的网站 - example.azurewebsites.net。 我将默认页面配置为index.html。 现在,网站假设拒绝未经身份验证的用户访问网站,但index.html和login.html除外。允许用户在窗体身份验证不会在azure网站工作

这是我的代码:

<system.webServer> 
    <defaultDocument> 
     <files> 
     <clear/> 
     <add value="index.html" /> 
     </files> 
    </defaultDocument> 
    </system.webServer> 
    <location path="index.html"> 
     <system.web> 
     <authorization> 
      <allow users="*"/> 
     </authorization> 
     </system.web> 
    </location> 
    <system.web> 
    <authentication mode="Forms"> 
     <forms loginUrl="login.html" defaultUrl="~/" /> 
    </authentication> 
    <authorization> 
     <deny users="?" /> 
    </authorization> 
    </system.web> 

example.azurewebsites.net/index.html - 这工作。 example.azurewebsites.net - 这不(重定向到login.html)。 但他们应该是一样的。 没有身份验证example.azurewebsites.net重定向到index.html没有问题。

我在哪里错了?

回答

0

我将默认页面配置为index.html。现在,该网站假设拒绝未经身份验证的用户访问网站,但index.html和login.html除外。

如果您想限制用户使用表单身份验证来访问应用程序中的网页,请参阅以下Web.config。

<location path="index.html"> 
    <system.web> 
    <authorization> 
     <allow users="*"/> 
    </authorization> 
    </system.web> 
</location> 

<system.web> 
    <compilation debug="true" targetFramework="4.5"> 
    <buildProviders> 
     <add extension=".html" type="System.Web.Compilation.PageBuildProvider" /> 
    </buildProviders> 
    </compilation> 
    <httpRuntime targetFramework="4.5"/> 

    <authentication mode="Forms"> 
    <forms loginUrl="login.html" name=".ASPXFORMSAUTH"> 
    </forms> 
    </authentication> 
    <authorization> 
    <deny users="?" /> 
    </authorization> 
</system.web> 

<system.webServer> 
    <handlers> 
    <add name="HTML" path="*.html" verb="GET, HEAD, POST, DEBUG" type="System.Web.UI.PageHandlerFactory" resourceType="Unspecified" requireAccess="Script" /> 
    </handlers> 
</system.webServer> 

example.azurewebsites.net/index.html - 这工作。 example.azurewebsites.net - 这不(重定向到login.html)。但他们应该是一样的。

请确定您是否指定index.html为default document

编辑:

example.azurewebsites.net - 这不(重定向到login.html的)。

我们可以创建一个URL重写规则,将用户从example.azurewebsites.net重定向到example.azurewebsites.net/index.html。

<rewrite> 
    <rules> 
    <rule name="redirecttoindexpage" stopProcessing="true"> 
     <match url="^$" /> 
     <action type="Redirect" url="/index.html" redirectType="Permanent"/> 
    </rule> 
    </rules> 
</rewrite> 
+0

谢谢。 index.html确实被指定为默认文档。其实,当我删除表单身份验证example.azurewebsites.net重定向到index.html没有问题。问题只在于表单身份验证。 – Dazhush

0

你可能希望检查的一件事是,如果你的web.config中存在以下内容。

<system.webServer> 
<modules runAllManagedModulesForAllRequests="true"> 
    <remove name="FormsAuthenticationModule" /> 
    <add name="FormsAuthenticationModule" type="System.Web.Security.FormsAuthenticationModule" /> 
</modules> 

您通常不必这样做,因为模块在C中定义:\ WINDOWS \ Microsoft.NET \ Framework64 \ v4.0.30319 \ CONFIG \ web.config文件在您的本地操作系统。但是,Azure Web Service环境并非如此。