网站不断重定向到ADFS

时间:2017-03-23 08:06:10

标签: c# asp.net-mvc single-sign-on owin adfs

我对整个SSO场景都比较陌生,如果这看似微不足道的话,请耐心等待 我似乎遇到了一个有点奇怪的问题,我不知道如何开始在任何地方查找它。

我正在使用ASP.NET MVC中的On-Premises选项为我的组织实现WS-Fed ADFS,它使用OWIN实现整个事情。

该实施工作正常,因为它适用于我的PC的Chrome浏览器,但不在其他地方。但我知道它有效,因为我能够通过Fiddler

捕获数据

Fiddler Info

您会注意到我的网站和ADFS之间连续来回,即使登录成功并且检索到的数据也是正确的。
几次反弹后,我收到错误页面

ADFS error
这是我的 Web.Config

sizeSelected()

RouteConfig.cs

import UIKit

class SecondViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate{

var crustSelected = "NY-Style"
var orderType = "Takeout"
let pickerViewArray = ["NY-Style","Stuffed","Chicago-Style","Neapolitan"];
var sauceChoice = "whole"
var pizzaSize = "small"
var order1Text = Bool()
var order2Text = Bool()



func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
    return 1
}

func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
    return pickerViewArray[row]
}

func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
    return pickerViewArray.count
}

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
    crustSelected = pickerViewArray[row]
}


@IBOutlet weak var orderTypeToggle: UISegmentedControl!
@IBOutlet weak var myPickerView: UIPickerView!
@IBOutlet weak var sauceChoiceToggle: UISegmentedControl!
@IBOutlet weak var sizeChoiceControl: UISegmentedControl!

    //I created this image outlet by connecting the image to the viewcontroller
@IBOutlet weak var myImageView: UIImageView!

@IBAction func indexChanged(sender: UISegmentedControl) {

    switch sauceChoiceToggle.selectedSegmentIndex
    {
    case 0:
        sauceChoice = "the whole";
    case 1:
        sauceChoice = "the left-side of the";
    case 2:
        sauceChoice = "the right-side of the";
    case 3:
        sauceChoice = "none of the";
    default: 
        break; 
    }

}


override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    var DestViewController : ThirdViewController = segue.destinationViewController as ThirdViewController



    if (DestViewController.order1Text == "" ) {
    DestViewController.order1Text = "\(pizzaSize) \(crustSelected) crust pizza, sauce on \(sauceChoice) pizza"
    } else {
    DestViewController.order2Text = "\(pizzaSize) \(crustSelected) crust pizza, sauce on \(sauceChoice) pizza"
    }



}


@IBAction func sizeSelected() {

    //I want to call the image resizing method here

}


@IBAction func SubmitOrderClicked(sender: AnyObject) {
    orderType = orderTypeToggle.titleForSegmentAtIndex(orderTypeToggle.selectedSegmentIndex)!

    pizzaSize = sizeChoiceControl.titleForSegmentAtIndex(sizeChoiceControl.selectedSegmentIndex)!

    var alertView:UIAlertView = UIAlertView()
    alertView.title = "Order Submitted"
    alertView.message = "You have successfully submitted a \(orderType) order for a \(pizzaSize) \(crustSelected) crust pizza, with sauce placed on \(sauceChoice) pizza."
    alertView.delegate = self
    alertView.addButtonWithTitle("OK")
    alertView.show()

}



override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


}

的HomeController

<configuration>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="ida:ADFSMetadata" value="https://xyz-test.azurewebsites.net/FederationMetadata/2007-06/federationmetadata.xml" />
    <add key="ida:Wtrealm" value="https://xyz-test.azurewebsites.net/" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2" />
  </system.web>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
</configuration>

我想了解如何解决这个问题。为什么/如何在我的PC的Chrome浏览器上工作呢?

2 个答案:

答案 0 :(得分:1)

已经很长时间了,但是我发现了导致此问题的原因。

这以及归因于使用OWIN登录ADFS的其他一些问题,特别是如果您使用的是Microsoft提供的默认代码,则是由于.NET 4.5中OWIN使用的默认cookie管理器中的错误。

找到了答案here公平地说,这不仅仅是解决方案,还是解决方案。

基本上,这使用SystemWebCookieManager作为自定义Cookie管理器,并且一切正常进行。

另外,您可以从here获取SystemWebCookieManager的代码,并且可以从here找到其依赖类。
注意:它看起来像是Katana项目中的代码,因此请确保还包括版权注释,并将这两个类包括在解决方案中。

从现在开始,ADFS就像往常一样,不需要进行任何更改(除非您正在做其他事情)。

答案 1 :(得分:0)

您似乎遇到了WsFederation Authentication login loop。我看到您通过http而不是https访问您的应用。