2023-02-16 358
我基本上需要登录使用ASP.NET成员资格的另一个域.
如果我们使用ASP.NET成员资格有ASP.NET Web应用程序,并且
另一方面,来自另一个域的HTML页面.
是否可以通过远程HTML页面登录ASP.NET网站.
我以前已经使用ColdFusion完成了此操作,但是ASP.NET会员资格使用了服务器控件.
欢呼!
在登录服务器控件下方,ASP.NET使用成员Hipprovider实现并形成ASP.NET成员资格的用户身份验证.您可以通过手动验证凭据然后将FormsAuthentication cookie连接到Response.
这里有一些资源可以帮助您入门:
您也可能会从反思Login控件的来源中受益,因此您可以了解当用户在使用服务器控件中登录时发生的确切事件顺序.这应该使您更容易理解如何为特定用例复制该功能.
作为旁注,我建议使用自定义IHttpHandler实现作为处理登录请求的注入点,但是有很多方法可以完成此任务.
下面是一个示例处理程序,您可以使用ASP.NET成员资格和formauthentication(就像服务器控件一样)来记录用户.
此代码假设:
请求页面具有指向web.config或路由中映射的URL/路由的表单,该页面上的表单包含a username输入字段,带有名称和a password输入字段,名称password.
public class LoginHandler : IHttpHandler
{
void IHttpHandler.ProcessRequest(HttpContext context)
{
string username = context.Request[" username"];="" string="" password="context.Request["password"];" if="" (!string.isnullorwhitespace(username)="" &&="" !string.isnullorwhitespace(password)="" &&="" membership.provider.validateuser(username,="" password))="" {="" formsauthentication.setauthcookie(username,="" true);="" renderuserloggedinresponse(context.response,username);="" }="" else="" formsauthentication.redirecttologinpage("loginfailure="1");" }="" private="" static="" void="" renderuserloggedinresponse(httpresponse="" response,="" string="" username)="" {="" response.write(string.format("you="" have="" logged="" in="" successfully,="" {0}!",="" username));="" response.end();="" }="" bool="" ihttphandler.isreusable="" {="" get="" {="" return="" true;="" }="" }="" }="">
原文链接:https://77isp.com/post/34009.html
=========================================
https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。
数据库技术 2022-03-28
网站技术 2022-11-26
网站技术 2023-01-07
网站技术 2022-11-17
Windows相关 2022-02-23
网站技术 2023-01-14
Windows相关 2022-02-16
Windows相关 2022-02-16
Linux相关 2022-02-27
数据库技术 2022-02-20
抠敌 2023年10月23日
嚼餐 2023年10月23日
男忌 2023年10月22日
瓮仆 2023年10月22日
簿偌 2023年10月22日
扫码二维码
获取最新动态