窗体身份验证不工作后发布 [英] Forms Authentication Not Working After Publish

查看:133
本文介绍了窗体身份验证不工作后发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力限制其访问特定的文件夹,以annonymous用户并允许访问该文件夹的那些记录在谁网站项目。
这一直是我的开发机器上完美的工作。

不过,由于发布网站,并部署到Web服务器(Windows Server 2008中,IIS7)窗体身份验证似乎并不奏效。匿名用户都能够访问限制级的文件夹。
我比较了 webconfig 同时在开发计算机和Web服务器,他们是完全一样的。

我设置了​​访问/限制使用此<一个使用Web站点管理工具的开发机器上的目录内置在.NET框架href=\"http://www.asp.net/web-forms/tutorials/deployment/users-and-roles-on-the-production-website-cs\"相对=nofollow>教程。不过,我明白这个工具仅本地主机?

请注意:我不使用asp.net登录和注册控件。我在后面的code。使用自定义功能(C#)

这方面的问题引起的位置变化?
在开发机器目录: C:\\用户\\威震\\文档\\ Visual Studio 2010的\\项目\\ Osqar - V0.2 \\ OSQARv0.1
Web服务器目录: C:\\的Inetpub \\ wwwroot的\\ Osqar

我有点丢在这里,因此任何意见​​将不胜AP preciated。

下面是Web配置文件

 &LT;?XML版本=1.0编码=UTF-8&GT?;
&LT;! -
  有关如何配置ASP.NET应用程序的更多信息,请访问:
  http://go.microsoft.com/fwlink/?LinkId=169433
   - &GT;
&LT;结构&gt;
    &LT;&是connectionStrings GT;
        &LT;添加名称=dbConn的connectionString =数据源= mssql.database.com;初始目录= devworks_oscar;用户ID =名为myusername;密码=密码的providerName =System.Data.SqlClient的/&GT;
    &LT; /&是connectionStrings GT;
    &LT;&的System.Web GT;
        &LT;身份验证模式=表格&GT;
            &LT;形式的名称=OsqarloginUrl =/登录/ login.aspx的保护=全部路径=/超时=60/&GT;
        &LT; /认证&GT;        &LT;编译调试=真/&GT;
        &LT;页面/></system.web>
    &LT; system.webServer&GT;
        &LT; defaultDocument&GT;
            &LT;&文件GT;
                &LT;增加价值=的Index.aspx/&GT;
            &LT; /文件&GT;
        &LT; / defaultDocument&GT;
    &LT; /system.webServer>
&LT; /结构&gt;


解决方案

将这个在&LT; cofiguraation&GT; 主要标记,如:

 &LT;结构&gt;
 &LT;位置路径=〜/ RestrictedFolder&GT;
  &LT;&的System.Web GT;
  &LT;授权&GT;
    &LT;拒绝用户= /&gt的帮助?
  &LT; /授权&GT;
  &LT; /system.web>
 &LT; /地点&gt;
....

如果你限制特定文件做的:

 &LT;位置路径=〜/ securedpage.aspx&GT;
  &LT;&的System.Web GT;
  &LT;授权&GT;
    &LT;拒绝用户= /&gt的帮助?
  &LT; /授权&GT;
 &LT; /system.web>
&LT; /地点&gt;

不要在部署项目中的这些变化在web.config

另外作为Wiktor的建议使用以阻止匿名访问的网站作为一个整体

把它放在&LT;的System.Web&GT; 可能之前或之后&LT;认证&GT; 标记

 &LT;授权&GT;
  &LT;拒绝用户= /&gt的帮助?
&LT; /授权&GT;

或者创建项目的根目录下的文件夹,并把安全的网页文件夹内。在文件夹上R-点击添加新的web.config文件,并把在以下的&LT;&的System.Web GT; 标签

 &LT;授权&GT;
  &LT;拒绝用户= /&gt的帮助?
&LT; /授权&GT;

I have been working on a website project which restricts access to a certain folder to annonymous users and allows access to the folder to those who are logged in. This has been working perfectly on my development machine.

However since publishing the website and deploying to a web server (Windows Server 2008, IIS7) the forms authentication appears not to be working. Anonymous users are able to access the "restricted" folder. I have compared the webconfig on both the development machine and the web server and they are exactly the same.

I set up the access/restriction to the directory on the development machine using the Web Site Administration Tool built into the .NET Framework using this tutorial. However I understand this tool is localhost only?

Please note: I am not using the asp.net login and registration controls. I am using a custom function in the code behind (C#)

Is this problem caused by the change of location? The development machine directory: C:\Users\Megatron\Documents\Visual Studio 2010\Projects\Osqar - v0.2\OSQARv0.1 The Web server Directory: C:\inetpub\wwwroot\Osqar

I am a little lost here so any advice would be greatly appreciated.

Here is the web config file

<?xml version="1.0" encoding="UTF-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
    <connectionStrings>
        <add name="dbConn" connectionString="data source=mssql.database.com; Initial Catalog=devworks_oscar;User ID=myusername;Password=password" providerName="System.Data.SqlClient" />
    </connectionStrings>
    <system.web>
        <authentication mode="Forms">
            <forms name="Osqar" loginUrl="/login/login.aspx" protection="All" path="/" timeout="60" />
        </authentication>

        <compilation debug="true" />
        <pages /></system.web>
    <system.webServer>
        <defaultDocument>
            <files>
                <add value="index.aspx" />
            </files>
        </defaultDocument>
    </system.webServer>
</configuration>

解决方案

Put this under <cofiguraation> main tag like:

<configuration>
 <location path="~/RestrictedFolder">
  <system.web>
  <authorization>
    <deny users="?"/>
  </authorization>
  </system.web>
 </location>
....

if you're restricting specific files do:

<location path="~/securedpage.aspx">
  <system.web>
  <authorization>
    <deny users="?"/>
  </authorization>
 </system.web>
</location>

Do these changes to the web.config in the deployed project

Alternatively as Wiktor suggested use to block anonymous access to the website as a whole

put it under <system.web> possibly before or after <authentication> tag

<authorization>
  <deny users="?"/>
</authorization>

Or create a folder under the root of your project and put secured pages inside that folder. R-click on the folder add new web.config file and put the following under the <system.web> tag

<authorization>
  <deny users="?"/>
</authorization>

这篇关于窗体身份验证不工作后发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆