简体   繁体   English

C#/ ASP.NET MVC:如果我知道用户名和密码,如何在其他Web应用程序中注册/登录?

[英]C#/ASP.NET MVC: how to register/log in a different web application if I know username & password?

I have a primary web app with authentication on example.com, and I have a secondary app with authentication on subdomain.example.com 我在example.com上有一个带有身份验证的主Web应用程序,在subdomain.example.com上有一个带有身份验证的辅助Web应用程序

I want the 2nd app to be integrated with the first one. 我希望第二个应用程序与第一个应用程序集成。 So once a user registers and logs in, s/he doesn't have to register/log in again. 因此,一旦用户注册并登录,他/他就不必再次注册/登录。

It is possible to send a post request, but this won't generate the cookies in user's browser... 可以发送发布请求,但这不会在用户的浏览器中生成Cookie。

How can I do that? 我怎样才能做到这一点?

Thanks 谢谢

You're able to set a cookie so that it works on all subdomains (www, subdomain, etc.). 您可以设置Cookie,使其可以在所有子域(www,子域等)上使用。 See Basics of Cookies in ASP.NET : 请参阅ASP.NET中的Cookie基础

By default, cookies are associated with a specific domain. 默认情况下,cookie与特定域关联。 For example, if your site is www.contoso.com, the cookies you write are sent to the server when users request any page from that site. 例如,如果您的站点是www.contoso.com,则当用户从该站点请求任何页面时,您编写的cookie就会发送到服务器。 (Except for cookies with a specific path value, as I explained in the section immediately preceding.) (如前所述,具有特定路径值的Cookie除外。)

You can also use the Domain property to create a cookie that can be shared among multiple subdomains. 您还可以使用Domain属性创建可以在多个子域之间共享的cookie。 For example, set the domain as follows: 例如,如下设置域:

Response.Cookies("domain").Value = DateTime.Now.ToString
Response.Cookies("domain").Expires = DateTime.Now.AddDays(1)
Response.Cookies("domain").Domain = "contoso.com"

The cookie will then be available to the primary domain as well as to sales.contoso.com and support.contoso.com. 然后,该Cookie将可用于主要域以及sales.contoso.com和support.contoso.com。

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

相关问题 我将如何通过传递电子邮件和密码从 Asp.Net MVC Web 应用程序登录到 slack - How i will log into slack from Asp.Net MVC web application by passing email and password 如何使用asp.net mvc c为web ste中的新用户注册创建激活链接# - How to create activate link for new user register in web ste using asp.net mvc c# 如何实例化C#TraceSources以记录(多线程)ASP.NET 2.0 Web应用程序(asmx ws)? - how to instantiate C# TraceSources to log (multithreaded) ASP.NET 2.0 Web application (asmx ws)? ASP.NET C#验证用户名和密码 - ASP.NET C# Validating username and password 如何以编程方式修改 ASP.NET MVC 和 C# 应用程序中的 web.config? - How to programmatically modify web.config in ASP.NET MVC and C# application? 如何在ASP.NET MVC Web应用程序的C#中管理图像文件 - how to manage image file in c# for asp.net mvc web-application 如何在Asp.net MVC Web应用程序c#中上传文件时显示进度? - How to show the progress while uploading a file in Asp.net MVC web application, c#? 如何将 C# 属性应用于 ASP.NET MVC Web 应用程序的列表内的类型 - How to apply C# Attributes to the type inside of a List for ASP.NET MVC Web Application 如何在一个ASP.NET MVC C#应用程序中使用两个具有关系的不同数据库 - How to use two different database with relation in one asp.net mvc c# application C#asp.net MVC用户名regex - C# asp.net mvc Username regex
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM