简体   繁体   English

从C#控制台应用程序调用Web服务。 该网站使用表单身份验证是安全的

[英]Calling Web Service from a C# Console application. The website is secure with form Authentication

I have a asp.net MVC 2 website. 我有一个asp.net MVC 2网站。 I would like to call a web page (http://localhost/main/SendEmail) with a C# Console Application. 我想使用C#控制台应用程序调用网页(http:// localhost / main / SendEmail)。

Is there a way to do this ? 有没有办法做到这一点 ?

In summary 综上所述
1 - C# Application Console Call A method in the website /main/SendEmail. 1-C#应用程序控制台调用网站/ main / SendEmail中的一种方法。
2 - The website is secure with Form authentication 2-网站通过表单身份验证是安全的
3 - I don't want to use the anonymous attribute, we need authenticate the user. 3-我不想使用匿名属性,我们需要对用户进行身份验证。

Does the webpage you are calling require an authenticated user? 您正在呼叫的网页是否需要经过身份验证的用户? If not, you could allow anonymous access to just that URL in the web.config: 如果不是,则可以允许匿名访问web.config中的该URL:

<location path="main/SendEmail">
  <system.web>
    <authorization>
      <allow users="*"/>
    </authorization>
  </system.web>
</location>

So first you have to post your credentials to the login page. 因此,首先您必须将凭据发布到登录页面。 Be sure to record all the cookies from the resultant HttpResponse. 确保记录结果HttpResponse中的所有cookie。 In all subsequent HttpRequests be sure to pass in all the recorded cookies. 在所有后续的HttpRequest中,请确保传递所有记录的cookie。

That should do it. 那应该做。

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

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