我遇到的情况是我需要访问使用ADFS进行身份验证的ASP.NET Web Api.我可以通过浏览器通过ADFS登录门户网站获取相关的FedAuth cookie,从而可靠地点击它.不幸的是,我需要从专用浏览器外部访问它,以便在移动应用中使用.该项目几乎是为工作和学校认证(内部部署)设置的标准visual studio web api模板的略微修改版本,并设置用于cookie认证.
来自Startup.Auth.cs的一些代码:
public void Configuration(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
Wtrealm = realm,
MetadataAddress = adfsMetadata
});
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = WsFederationAuthenticationDefaults.AuthenticationType
});
}
Run Code Online (Sandbox Code Playgroud)
我似乎无法弄清楚从哪里开始.我已尝试从ADFS请求访问令牌,并可使用相关登录信息获取不同版本的SAML断言,但它会被Web API拒绝.我误解了它应该如何工作吗?
从我的理解,它应该是这样的: 我认为它应该工作
这就是我现在正在试图弄清楚如何获得正确的令牌.
using System;
using System.IdentityModel.Protocols.WSTrust;
using System.IdentityModel.Tokens;
using System.Net;
using System.Net.Http;
using System.ServiceModel;
using System.ServiceModel.Security;
using Thinktecture.IdentityModel.Extensions;
using Thinktecture.IdentityModel.WSTrust;
namespace ConsoleApplication1
{
class Program
{
private const string UserName = "USERNAME";
private const string …Run Code Online (Sandbox Code Playgroud) 在 ASP.NET MVC Core 中回发视图模型时是否可能以某种方式不清除文件输入?我知道 IFormFile 不包含指定所选文件目录的成员。
因此,如果视图模型在 ModelState 无效的情况下被发送回,则文件输入将被清除。是否可以在不完全诉诸客户端验证的情况下避免这种情况?
这是一个示例控制器和模板,可以更充分地解释我所说的内容
控制器:
namespace Example
{
public class CreateVm
{
public IFormFile aFile{ get; set; }
public string someText{get; set;}
}
public class ExampleController : Controller
{
public IActionResult Action()
{
var vm = new CreateVm();
return View(vm);
}
[HttpPost]
public IActionResult Create(CreateVm vm)
{
// Something invalidates the model state
// The supplied viewmodel isn't valid, send it back
if (!ModelState.IsValid)
return View(vm);
// Do stuff here
return RedirectToAction(nameof(Create));
} …Run Code Online (Sandbox Code Playgroud)