【发布时间】:2016-07-20 20:18:59
【问题描述】:
我需要在我闪亮的新 ASP.Net Core Web API + Angular2 项目中使用由旧 VB.Net aspx 项目创建的身份验证 cookie。我对基于 cookie 的授权和身份验证非常陌生,我公司中没有人知道如何将他们知道的内容转化为我正在尝试做的事情。
几天的研究和修修补补让我走到了这一步: 现在,我可以在任何需要的地方设置 [Authorize] 属性并阻止访问返回通常的 401 错误,但我的网站似乎没有将他的网站创建的 cookie 识别为该锁的众所周知的钥匙......
在 Startup.cs - 我没有在“Configure()”方法之外做任何事情,我应该这样做吗?
我正在将站点配置为使用 cookie 身份验证,将方案设置为“Cookies”,但不知道具体是做什么的,并将“CookieName”设置为从该旧站点登录创建的身份验证 cookie 的名称。
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
// Stuff eliminated for brevity
// Set up pipeline
app.UseDefaultFiles();
app.UseStaticFiles();
//app.UseIdentity(); (Don't think I need this??)
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationScheme = "Cookies", //(Dont actually know what this does. Should I create my own middlewares? I mean what is this magic string "Cookies"? It's just from tutorials/examples...)
LoginPath = new PathString("/base_site/login.aspx"),
AccessDeniedPath = new PathString("/base_site/logon.aspx"), // Might want to create an error page...
CookieName = "companyName_AccessLevel", //This is what he had in <forms name="companyName_AccessLevel">
ReturnUrlParameter = "index.html", //What youd put in <forms defaultUrl="index.html">
AutomaticAuthenticate = true,
AutomaticChallenge = true
});
app.UseMvc();
}
坦率地说,与我的同事根据他的 asp.net 经验提出的建议相比,这一切似乎非常复杂:
“只要把它放在你的 web.config 中”他告诉我
<system.web>
<authentication mode="Forms">
<forms name="companyName_AccessLevel" loginUrl="/base_site/login.aspx" protection="All" timeout="60" defaultUrl="index.html"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
所以他当然不太热衷于和我一起研究这种“其他方式”。我可以以某种方式恢复到 web.config 吗?
【问题讨论】:
标签: c# asp.net vb.net authentication asp.net-core