简体   繁体   English

从同一站点访问受密码保护的站点上的.ASPX页

[英]Accessing .ASPX page on password protected site from within same site

We recently migrated our staging server to a new hosting provider and setup forms authentication from within the hosting account control panel so that crawlers and unwanted visitors could not access it. 最近,我们将登台服务器迁移到了新的托管服务提供商,并从托管帐户控制面板中设置了表单身份验证,以便爬网程序和不需要的访问者无法访问它。

Now we are finding at least one area of the site's logic that is failing due to HTTP 401 Unauthorized. 现在,我们发现至少一部分站点逻辑由于HTTP 401未经授权而失败。

There is a section of the site that generates PDF for site users. 该网站的一部分为网站用户生成PDF。 The conversion is from HTML to PDF. 转换是从HTML到PDF。 The source pages are .ASPX written in C#. 源页面是用C#编写的.ASPX。 The generate .HTM by downloading the ASPX files using their URL, such as http://www.mysite.com/mypage.aspx . 通过使用URL下载ASPX文件(例如http://www.mysite.com/mypage.aspx)来生成.HTM。

Now that the site is password protected, these routines fail with the HTTP 401 and I'm not sure how to overcome this. 现在,该站点已受密码保护,这些例程在HTTP 401中失败,并且我不确定如何解决此问题。 We don't want to remove the site authentication because we don't want anything accessing it. 我们不想删除站点身份验证,因为我们不希望任何内容访问它。

Can anyone point me on how to code around this so that our internal routines will have access to local pages like we need? 谁能指出我该如何编码,以便我们的内部例程可以按需要访问本地页面?

EDIT 编辑

Some more detail. 一些细节。 Since this is just a development site, I performed a quick and dirty configuration from within the hosting provider's control panel to enable Folder Security. 由于这只是一个开发站点,因此我在托管服务提供商的控制面板中执行了快速而肮脏的配置,以启用文件夹安全性。 I added the root folder '/' and then created 2 users. 我添加了根文件夹“ /”,然后创建了2个用户。 This works fine. 这很好。 When I go to the site I am prompted with what appears to be a forms authentication dialog box. 当我转到该站点时,系统会提示我一个似乎是表单身份验证对话框的窗口。 I enter my username and password, access is granted. 输入用户名和密码,授予访问权限。

I've noted that this configuration created 4 files in my root /' web site folder. 我已经注意到,此配置在我的root /'网站文件夹中创建了4个文件。 They are .htaccess, .htpasswd, .htgroup, and .htfolders. 它们是.htaccess,.htpasswd,.htgroup和.htfolders。 This site has a lot of folders. 这个站点有很多文件夹。 Configuring each one in this manner would be time consuming and tedious. 以这种方式配置每个服务器既费时又繁琐。 Therefore the '/' root configuration. 因此是“ /”根配置。

Our purpose is to block access to crawlers/search engines and also casual visitors who stumble onto the hostname. 我们的目的是阻止访问爬虫/搜索引擎以及偶然发现主机名的临时访问者。

This configuration causes the side effect that a small part of the site can no longer access it's own pages via http:// without getting an HTTP 401 error. 这种配置会带来副作用,即该站点的一小部分无法再通过http://访问其自身的页面,而不会出现HTTP 401错误。 What I would love to do is configure all of this using <security><ipSecurity> , blacklist all except for myself and the web site, but the provider doesn't install the needed IP module to do this. 我想做的是使用<security><ipSecurity>配置所有这些,将除我本人和网站之外的所有黑名单都列入黑名单,但是提供商没有安装所需的IP模块来执行此操作。

The C# code that is receiving the HTTP 401 is: 接收HTTP 401的C#代码为:

webrequest = (HttpWebRequest)WebRequest.Create(url);
webrequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)";
webrequest.Timeout = 600000;
resp = webrequest.GetResponse();

I've also tried: 我也尝试过:

CredentialCache credCache = new CredentialCache();
credCache.Add(new Uri(url), "Basic", new NetworkCredential("username", "password"));
webrequest = (HttpWebRequest)WebRequest.Create(url);
webrequest.Credentials = credCache;
webrequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)";
webrequest.Timeout = 600000;
resp = webrequest.GetResponse();

Both methods receive HTTP 401 Unauthorized. 两种方法均会收到未经授权的HTTP 401。 I really don't want to fix this in the C# code because this security issue will not exist on the live site. 我真的不想在C#代码中修复此问题,因为此安全问题在实时站点上将不存在。 I would much rather perform this configuration in web.config and/or the .ht* files if needed. 如果需要,我宁愿在web.config和/或.ht *文件中执行此配置。

So, I am wondering, is there anything I can place in web.config that will help? 因此,我想知道,在web.config中是否可以放置任何有用的东西? Does anyone see a problem the way this is setup? 有人看到这种设置方式的问题吗? (Other than it's not working! :P) (除了它不起作用!:P)

If you want you can remove authentication for just one page as follows. 如果需要,可以按如下所示仅删除一页的身份验证。

<location path="mypage.aspx">
    <system.web>
        <authorization>
            <allow users="*"/>
        </authorization>
    </system.web>
</location>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM