C# 从控制台应用程序在 ASP.Net 表单授权网站上进行身份验证
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Authenticate on an ASP.Net Forms Authorization website from a console app
提问by saalon
I'm trying to build a C# console application to automate grabbing certain files from our website, mostly to save myself clicks and - frankly - just to have done it. But I've hit a snag that for which I've been unable to find a working solution.
我正在尝试构建一个 C# 控制台应用程序来自动从我们的网站抓取某些文件,主要是为了节省自己的点击次数 - 坦率地说 - 只是为了完成它。但是我遇到了一个障碍,我一直无法找到可行的解决方案。
The website I'm trying to which I'm trying to connect uses ASP.Net forms authorization, and I cannot figure out how to authenticate myself with it. This application is a complete hack so I can hard code my username and password or any other needed auth info, and the solution itself doesn't need to be something that is viable enough to release to general users. In other words, if the only possible solution is a hack, I'm fine with that.
我尝试连接的网站使用 ASP.Net 表单授权,我无法弄清楚如何使用它来验证自己的身份。这个应用程序是一个完整的黑客,所以我可以硬编码我的用户名和密码或任何其他需要的身份验证信息,并且解决方案本身不需要是足够可行的东西来发布给一般用户。换句话说,如果唯一可能的解决方案是 hack,我就可以接受。
Basically, I'm trying to use HttpWebRequest to pull the site that has the list of files, iterating through that list and then downloading what I need. So the actual work on the site is fairly trivial once I can get the website to consider me authorized.
基本上,我正在尝试使用 HttpWebRequest 来拉取具有文件列表的站点,遍历该列表,然后下载我需要的内容。因此,一旦我可以让网站认为我获得授权,网站上的实际工作就相当简单。
回答by Espo
回答by hova
I have dealt with something similar, and the hardest part is figuring out exactly what you needed to "fake" to get authorized. In my case it was authorizing into some Lotus Notes webservice, but the details are unimportant, the method is the same.
我处理过类似的事情,最困难的部分是弄清楚你需要“伪造”什么才能获得授权。在我的例子中,它是授权到一些 Lotus Notes webservice,但细节并不重要,方法是一样的。
Essentially, we need to record a regular user session. I would recommend Fiddler http://www.fiddler2.combut if you're on linux or something, then you'll need to use wireshark to figure some of the things out. Not sure if there is a firefox plugin that could be used.
本质上,我们需要记录一个普通的用户会话。我会推荐 Fiddler http://www.fiddler2.com但如果你使用的是 linux 或其他东西,那么你需要使用 wireshark 来解决一些问题。不确定是否有可以使用的 firefox 插件。
Anyway, start up IE, then start up Fiddler. Complete the login process.
Stop what you're doing. Switch to the fiddler pane, and examine the recorded sessions in detail. It should give you exactly what you need to fake using WebRequests.
无论如何,启动IE,然后启动Fiddler。完成登录过程。
停止你正在做的事情。切换到 fiddler 窗格,并详细检查录制的会话。它应该准确地为您提供使用 WebRequest 进行伪造所需的内容。